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?
The Progress<T>.ProgressChanged
event has a delegate of type EventHandler<T>
, which has this signature:
public delegate void EventHandler<TEventArgs>(
Object sender,
TEventArgs e
)
Change your code to this:
public void HandleProgressChanged(Object sender, ProgressReport report)
{
// do stuff
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.