C# 使用webclient异步下载文件时DownloadFileCompleted事件不起作用

C# 使用webclient异步下载文件时DownloadFileCompleted事件不起作用,c#,webclient,C#,Webclient,我正在使用Webclient异步下载4个文件。问题是在这个场景中,当任何文件完成时,它都不会触发FileCompletedEvent 不要担心代码,我已经删除了很多额外的代码。它必须一次对单个文件有效 Dictionary<int, WebClient> wd = new Dictionary<int, WebClient>(); public void DownloadPDF(string url,string path) { index

我正在使用Webclient异步下载4个文件。问题是在这个场景中,当任何文件完成时,它都不会触发FileCompletedEvent

不要担心代码,我已经删除了很多额外的代码。它必须一次对单个文件有效

 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;
    }
Dictionary wd=new Dictionary();
public void DownloadPDF(字符串url、字符串路径)
{
指数=1;
if(wd.ContainsKey(1)=false)
{
wd.Add(1,空);
}
对于(int i=1;i w_DownloadFileCompleted)(发送方,e,路径,索引);
wd[index].DownloadFileAsync(新Uri(url),路径);
}
私有void w_DownloadFileCompleted(对象发送方,System.ComponentModel.AsyncCompletedEventArgs e,字符串路径,int索引)
{
wd[index]=null;
}

在下载并发文件的情况下,这个问题与其他问题不同。谢谢你,你给AsyncCompletedEventHandler一个机会了吗?

@LasseV.Karlsen对不起,这已经是本地问题了。我只是在处理代码时把行的位置放错了,这意味着什么,对不起,我不明白