向 C#4 中的 ProgressChanged 事件添加额外参数
add extra parameter to ProgressChanged event in C#4
这是我的代码(简单下载器):
public void DownloadFile(string urlAddress, string location)
{
using (webClient = new WebClient())
{
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
Uri URL = urlAddress.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri(urlAddress) : new Uri("http://" + urlAddress);
try
{
webClient.DownloadFileAsync(URL, location);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
& 这是我的问题:
如何向我的 ProgressChanged
事件添加额外参数 (int RowNumber
)?我的意思是这样的:
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e, int RowNumber)
{
// Other codes here
}
& 这是 VS2010 给我的错误:
No overload for 'ProgressChanged' matches delegate
'System.Net.DownloadProgressChangedEventHandler'
我应该覆盖 DownloadProgressChangedEventHandler
吗?!怎么办?!
谢谢你帮我。
你应该改变这个:
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
与:
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) => ProgressChanged(sender, e, RowNumber));
这是我的代码(简单下载器):
public void DownloadFile(string urlAddress, string location)
{
using (webClient = new WebClient())
{
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
Uri URL = urlAddress.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri(urlAddress) : new Uri("http://" + urlAddress);
try
{
webClient.DownloadFileAsync(URL, location);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
& 这是我的问题:
如何向我的 ProgressChanged
事件添加额外参数 (int RowNumber
)?我的意思是这样的:
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e, int RowNumber)
{
// Other codes here
}
& 这是 VS2010 给我的错误:
No overload for 'ProgressChanged' matches delegate 'System.Net.DownloadProgressChangedEventHandler'
我应该覆盖 DownloadProgressChangedEventHandler
吗?!怎么办?!
谢谢你帮我。
你应该改变这个:
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
与:
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) => ProgressChanged(sender, e, RowNumber));