Well, I really don’t know what is wrong with my code, and what happens like this.
class Activity has the following methods
protected struct EventParams { public object sender; public EventArgs e; } private EventParams WaitEventRaise_Body(ref EventHandler<EventArgs> handler, int timeout) { AutoResetEvent receiver = new AutoResetEvent(false); EventParams result = new EventParams(); EventHandler<EventArgs> handle = new EventHandler<EventArgs>((sender, e) => { result.e = e; result.sender = sender; receiver.Set(); }); handler += handle; if (timeout > 0) { receiver.WaitOne(timeout); } else { receiver.WaitOne(); } return result; } protected EventParams WaitEventRaise(ref EventHandler<EventArgs> handler) { return WaitEventRaise_Body(ref handler, -1); } protected EventParams WaitEventRaise(ref EventHandler<EventArgs> handler, int timeout) { return WaitEventRaise_Body(ref handler, timeout); }
So, I find myself writing AutoResetEvent again and again, so I decided to create a method. But when I try to call this method from the derived class Bot : Activity
EventParams eventResult = WaitEventRaise(ref currentJob.JobReported);
gives
Error 30 The best overloaded method matching for Project.Activity.WaitEventRaise (ex System.EventHandler) has some invalid arguments
currentJob is a Job : Activity class that has an event
public event EventHandler<JobReport> JobReported;
and
class JobReport : EventArgs
What I want to do is that the bot does the job, actually creates jobs and waits for them to finish their work. The Job class fires an event inside so that the bot class notices that it has completed its work. And the bot class waits until work triggers an event. Therefore, I hope this is clear. And I'm sorry that English is not my native language.
source share