Tag: downloadfileasync

WebClient DownloadFileAsync挂起

美好的一天。 我正在使用DownloadFileAsync处理文件下载器类。 在正常情况下一切正常。 但是当我下载文件并禁用网络连接时,下载进度只是停止无限时间,不会引发任何错误或调用任何回调。 任何想法如何处理这种情况? 非常感谢。 _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上一切正常。

WebClient.DownloadProgressChanged:Console.WriteLine()阻止UI线程

我有以下简单的代码: private void btn_download_Click(object sender, EventArgs e){ WebClient client = new WebClient(); client.DownloadProgressChanged += client_DownloadProgressChanged; client.DownloadFileAsync(new Uri(“http://…/file.zip”), “file.zip”); } void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e){ //Prints: “Downloaded 3mb of 61.46mb (4%)” Console.WriteLine(“Downloaded ” + ((e.BytesReceived / 1024f) / 1024f).ToString(“#0.##”) + “mb” + ” of ” + ((e.TotalBytesToReceive / 1024f) / 1024f).ToString(“#0.##”) + “mb” + ” (” […]

如何在.net上为WebClient设置TimeOut?

我下载了一些文件,但我也想为webclient设置超时。 正如我所看到的那样,我们可以使用重写WebRequest。 我已经做了但它没有用。 我的意思是重写GetWebRequest方法不起作用..这是我的代码 public class VideoDownloader : Downloader { /// /// Initializes a new instance of the class. /// /// The video to download. /// The path to save the video. public VideoDownloader(VideoInfo video, string savePath) : base(video, savePath) { } /// /// Starts the video download. /// public override void Execute() { // […]

使用webclient.DownloadFileAsync下载的文件有0KB

我正在尝试使用WebClient下载zend-framework(来自http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip ) string url = “http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip”; WebClient downloader= new WebClient(); downloader.DownloadFileAsync(new Uri(url), “C:\\temp.zip”); 该文件已创建,但它是空的。 我使用fiddler检查了响应,我得到HTTP 200,正确的内容长度,但“connection:closed”,fiddler在“body”列中显示“-1”。 我尝试将用户代理(从谷歌浏览器请求复制)和“连接:保持活动”添加到标题,但这些都没有帮助。 我也很确定,我的程序使用相同的URL一次或两次下载此文件。 WebClient触发的事件没有错误。 有任何想法吗?