add extra parameter to ProgressChanged event in C#4

∥☆過路亽.° 提交于 2019-12-23 04:17:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!