在C#4中为ProgressChanged事件添加额外参数

时间:2015-01-02 23:46:36

标签: c# webclient

这是我的代码(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);
            }
        }
    }

&安培;这是我的问题:

如何在我的int RowNumber活动中添加额外参数(ProgressChanged)?我的意思是这样的:

private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e, int RowNumber)
    {
           // Other codes here
    }

&安培;这是VS2010给我的错误:

  

' ProgressChanged'匹配代表   ' System.Net.DownloadProgressChangedEventHandler'

我应该覆盖DownloadProgressChangedEventHandler吗?!怎么样?!

感谢您帮助我。

1 个答案:

答案 0 :(得分:2)

你应该改变这个:

webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

使用:

webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) => ProgressChanged(sender, e, RowNumber));