Closed AZnait closed 2 months ago
ActionEventHandler is executed after ExcuteEventClass.SignalEvent.WaitOne(). use AsyncEventHandler and await/async keywords
await eventHandler.RaiseAsync(application => ExcuteEventClass.ExcuteMyEvent());
ExcuteEventClass.SignalEvent.WaitOne();
ExcuteEventClass.SignalEvent.Reset();
Unfortunately, using the AsyncEventHandler the worker completes before even going through the event and when the ReportProgress is called it throws Operation already completed exceptiopn.
private async Task Worker_DoWork(object sender, DoWorkEventArgs e)
{
ExcuteEventClass.Worker=worker;
await eventHandler.RaiseAsync(application => FindMyRoomUsingSpaceEvent.ExcuteFindMySpaceEvent());
ExcuteEventClass.SignalEvent.WaitOne();
ExcuteEventClass.SignalEvent.Reset();
}
You can then move SignalEvent
eventHandler.Raise(application =>
{
ExcuteEventClass.ExcuteMyEvent()
ExcuteEventClass.SignalEvent.WaitOne();
ExcuteEventClass.SignalEvent.Reset();
});
inside the lambda Raise() method
Doing this causes the same behavior as raising the event Asynchronously, the worker completes its work before going through the code block.
I can recommend only debugging, without debugging it is not obvious to understand the mechanics of this code functioning
At first, thank you for taking the time and effort to create such a helpful toolkit. I have a question rather than an Issue. I'm trying to update a WPF progress bar through a long-running process that is happening inside an ActionEventHandler which is raised inside a ViewModel and all running with no problems except that the progress gets updated at the end and not incrementally. Here is a sample of my code. Any pointers of how I can get it working would be very helpful.
Regards, Ahmad