我在使用php脚本翻译单词并将结果字符串下载到.TextBox
我的程序有两个文本框
txtWord
,txtTranslatedWord
这就是简化的代码
WebClient c = new WebClient();
private void txtWord_TextChanged(object sender, EventArgs e)
{
string response = c.DownloadString("http://example.com/Services/Translator/lang/EnglishToArabic.php?Word=" + txtWord.Text);
switch (response.ToLower())
{
case "not exist":
{
txtTranslatedWord.Text = "{Sorry but no translation for this word!}";
break;
}
default:
{
txtTranslatedWord.Text = response;
break;
}
}
}
问题是当文本更改时程序滞后并且看起来它会停止工作。
该程序运行成功,但滞后了这么多,特别是如果作者写得这么快。
我试着BackgroundWorker
做一个延迟,比如当用户停止写作 2 秒然后程序开始翻译但仍然没有任何运气的情况下仍然滞后。
有没有什么简单的方法可以毫无问题地做到这一点?