晚上好,我尝试在 DownloadProgressChangedEventHandler 的基础上创建一个自己的 EventHandler。原因是,我想给回调函数一个额外的参数(文件名)。这是我的事件处理程序:
public class MyDownloadProgressChangedEventHandler : DownloadProgressChangedEventHandler
{
public object Sender { get; set; }
public DownloadProgressChangedEventArgs E { get; set; }
public string FileName { get; set; }
public MyDownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs e, string fileName)
{
this.Sender = sender;
this.E = e;
this.FileName = fileName;
}
}
这是我的尝试:
WebClient client = new WebClient();
client.DownloadProgressChanged += new MyDownloadProgressChangedEventhandler(DownloadProgressChanged);
client.DownloadFileAsync(new Uri(String.Format("{0}/key={1}", srv, file)), localName);
Console.WriteLine(String.Format("Download of file {0} started.", localName));
Console.ReadLine();
但是 VS 说从 MyDownloadProgressChangedEventHandler 到 DownloadProgressChangedEventHandler 的对话是不可能的。这甚至可能像我想的那样吗?
提前致谢。