WebClient DownloadFileAsync挂起 [英] WebClient DownloadFileAsync hangs

查看:225
本文介绍了WebClient DownloadFileAsync挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天。
我的文件下载使用类工作DownloadFileAsync。
在正常情况下,一切工作正常。
,而当我下载文件,并禁用网络连接,下载进度只是停止了无限的时间,没有提出任何错误或调用任何回调。
任何想法如何处理这种情况?
非常感谢

Good day. I'm working on file downloader class using DownloadFileAsync. In normal situations everything works fine. But when I'm downloading file and disable network connection, downloading progress is just stops for infinite time, without raising any errors or calling any callbacks. Any ideas how to handle this situation? Many thanks.

_client.Proxy = WebRequest.DefaultWebProxy;
_client.DownloadProgressChanged += (sender, argv) => { actionCallback(argv.ProgressPercentage); }
_client.DownloadFileCompleted += (sender, argv) => { 
      if (argv.Error != null) { 
          _exc = argv.Error;
      } 
      set event
}
 Task.Factory.StartNew(() => {
     _client.DownloadFileAsync(request, targetFileName);

     thread sync

     if (_exc != null) {
         logger.ErrorException(exc);
         throw;
     }

出现在Vista和2K8这一问题,Win7的一切正常。

The problem appears under Vista and 2k8. On Win7 everything is ok.

推荐答案

事件处理程序添加到的 WebClient.OpenReadCompleted 事件。该OpenReadCompletedEventArgs有一个布尔属性错误,如果发生错误。

Add an event handler to the WebClient.OpenReadCompleted event. The OpenReadCompletedEventArgs has a boolean property for Error if an error occurred.

这篇关于WebClient DownloadFileAsync挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆