问题
Here is my code (Simple Downloader):
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);
}
}
}
& Here is my question:
How to add extra parameter (int RowNumber
) to my ProgressChanged
event? I mean like this:
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e, int RowNumber)
{
// Other codes here
}
& Here is the error that VS2010 gives me:
No overload for 'ProgressChanged' matches delegate 'System.Net.DownloadProgressChangedEventHandler'
should I override DownloadProgressChangedEventHandler
?! how?!
Thanks for helping me out.
回答1:
You should change this:
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
with:
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) => ProgressChanged(sender, e, RowNumber));
来源:https://stackoverflow.com/questions/27750150/add-extra-parameter-to-progresschanged-event-in-c4