【发布时间】:2015-08-25 18:45:37
【问题描述】:
我有一个WebClient 正在下载一个 .chm 文件(如下面的代码所示)。下载的内容似乎非常不规则。完整文件大小约为 2500-2600 KB,但大约 50-75% 的时间我会返回较小的文件(一些示例:1233 KB、657 KB、353 KB、1745 KB 等)。
(代码已简化/个人详细信息已删除)
public static void DownloadMyFile(string destFileAndPath)
{
//Get base for help Url, stop at first "/" ignoring "https://", then add path in server
string Url = "https://mywebservice.com/myFile.chm";
using (var client = new WebClient())
{
//I need to do stuff to the downloaded file when done
client.DownloadFileCompleted += client_DownloadFileCompleted;
client.DownloadFileAsync(new Uri(Url), destFileAndPath);
//More waiting?
while (client.IsBusy) { }
}
}
还有事件,它工作正常,但在一个“未完成”的文件上:
public static void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
//Do stuff like comparing the file to another, renaming, copying, etc.
}
我真的错过了什么吗?
【问题讨论】:
-
您是否在检查
AsyncCompletedEventArgs e的内容,尤其是Cancelled和Error属性? -
啊!我只是检查
Cancelled。看起来Error正在返回,但有某种异常(我将不得不进一步调查)。
标签: c# webclient downloadfileasync