1

I am trying to implement the Async Progress Pattern to my program. But I am stuck at a rather embarassing point: I am unable to assign the event Handler.

My code looks like this: The event is handeld in an extra window:

public ProgressReportViewModel(IWindowManager windManager, Progress<ProgressReport> progressReport)
{
    this.ProgressReport = progressReport;
    this.ProgressReport.ProgressChanged += HandleProgressChanged;
}

    public void HandleProgressChanged(ProgressReport report)
    {

// do stuff. }

If I am trying to compile, I get the following error: No overload for 'HandleProgressChanged' matches delegate 'System.EventHandler'

Why does this error occur? Do I have a flaw in my understanding of Event handlers?

4

1 回答 1

2

Progress<T>.ProgressChanged事件有一个类型为 的委托EventHandler<T>,其签名如下:

public delegate void EventHandler<TEventArgs>(
    Object sender,
    TEventArgs e
)

将您的代码更改为:

public void HandleProgressChanged(Object sender, ProgressReport report)
{
    // do stuff
}
于 2013-08-01T12:34:10.993 回答