如何解决DownloadStringAsync不会异步下载字符串
|| 尝试实现“ 0”以防止在下载一个字节的数据时UI冻结10秒。但是,即使下载完成,它也会冻结UI,就像我使用downloadString()
一样。
这是我的代码:
public void loadHTML()
{
WebClient client = new WebClient();
// Specify that the DownloadStringCallback2 method gets called
// when the download completes.
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(loadHTMLCallback);
client.DownloadStringAsync(new Uri(\"http://www.example.com\"));
return;
}
public void loadHTMLCallback(Object sender,DownloadStringCompletedEventArgs e)
{
// If the request was not canceled and did not throw
// an exception,display the resource.
if (!e.Cancelled && e.Error == null)
{
string result = (string)e.Result;
// Do cool stuff with result
}
}
解决方法
遇到同样的问题,找到了解决方法。
这里的讨论非常复杂:
http://social.msdn.microsoft.com/Forums/zh-CN/a00dba00-5432-450b-9904-9d343c11888d/webclient-downloadstringasync-freeze-my-ui?forum=ncl
简而言之,问题在于Web客户端正在搜索代理服务器并挂起该应用程序。
以下解决方案有帮助:
WebClient webClient = new WebClient();
webClient.Proxy = null;
... Do whatever else ...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。