我使用Webclient异步下载4个文件。问题是,在这个情景中,当任何文件完成时,它不会触发FileCompletedEvent。DownloadFileCompleted事件不工作,而异步使用webclient下载文件
不要担心代码,我已经删除了很多额外的代码。它必须在一个时间
Dictionary<int, WebClient> wd = new Dictionary<int, WebClient>();
public void DownloadPDF(string url,string path)
{
index=1;
if (wd.ContainsKey(1) == false)
{
wd.Add(1, null);
}
for (int i = 1; i <=5; i++)
{
if (wd[i] == null)
{
wd[i] = new WebClient();
index = i;
break;
}
}
wd[index].DownloadFileCompleted += (sender, e) => w_DownloadFileCompleted(sender, e, path,index);
wd[index].DownloadFileAsync(new Uri(url), path);
}
private void w_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e, string path,int index)
{
wd[index] = null;
}
这个问题不同于其他在下载并发的情况下的情况下,对单个文件文件。谢谢
@ LasseV.Karlsen对不起,这已经是本地的了。我只是在处理代码时错位了行的位置 – Charlie 2015-02-12 06:51:19