I want to pass an event into a method. The code I have is as follows, but what do I put for the type "XXX" ?
internal class Retriever<TEventArgs> where TEventArgs : EventArgs
{
public Retriever( XXX event, EventHandler<TEventArgs> handler )
{
_event = event;
_handler = handler;
_event += handler;
}
XXX _event;
EventHandler<TEventArgs> _handler;
}
Edit: Elaboration of the question. I'm trying to write a generic event guard, where the event is subscribed to prior to an event occurring, and unsubscribed after the event has occurred. This class would look like:
internal class EventGuard<TEventArgs> : IDisposable where TEventArgs : EventArgs
{
public Retriever( XXX event, EventHandler<TEventArgs> handler )
{
_event = event;
_handler = handler;
_event += handler;
}
XXX _event;
EventHandler<TEventArgs> _handler;
public void Dispose()
{
_event -= _handler;
}
}
and I would use it the following way. Proxy.RetrieveAsync
is a web method, which upon completion would cause the Proxy.RetrieveCompleted
event to be fired. The body of the completion handler HandleRetrieveCompleted
, which is not shown, would call Set() on the ManualResetEvent (passed in as the UserState object).
using ( new EventGuard<EventArgs>( Proxy.RetrieveCompleted, new EventHandler<EventArgs>( HandleRetrieveCompleted) ) )
{
ManualResetEvent resetEvent = new ManualResetEvent();
Proxy.RetrieveAsync(resetEvent);
resetEvent.WaitOne();
}