0

My application is used to download files. After the files are downloaded, the size of those files is compared to elements in an XML file for validation. The XML file has an element for each file with a "size" attribute. This is the size that the downloaded file is supposed to be. The files validate fine on a normal Ethernet connection. When a slow wireless connection is used, files are constantly failing validation, meaning the downloaded files are not the size they're supposed to be. Why is it that the WebClient DownloadFileAsync() method cannot successfully download a file on a slow or unstable network? Is there any way around this besides retrying over and over?

foreach (var file in fileList.OrderBy(x => x.Name))
{
    var client = new WebClient();
    client.DownloadFileCompleted += (o, a) => Task.Factory.StartNew(() => OnDownloadFileCompleted());
    client.DownloadFileAsync(new Uri(AppStrings.FileServer + file.Name), AppStrings.FilePath + file.Name);
    webClientList.Add(client); //used to dispose later, after all files complete.
}
4

1 回答 1

0

您试图一次下载太多文件。尝试分批下载。AsyncDownloadCompleted Event 对象上还有一个错误属性,它将告诉您异常是什么。

于 2013-04-13T03:01:14.207 回答