Re: Delegates/events
- From: "PS" <ecneserpegats@xxxxxxxxxxx>
- Date: Fri, 23 Mar 2007 16:35:30 -0400
"Peter Larsen []" <PeterLarsen@xxxxxxxxxxxxxxxx> wrote in message
news:u$hylEWbHHA.4872@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I have a problem passing an event in a method call.
Please see the following sample:
//This class holds information about listeners (in MyEvent).
public class First
{
public event EventHandler<EventArgs> MyEvent;
}
//This class could be a worker-thread.
public class Second
{
public void Method(First aInstance)
{
Third th = new Third();
th.AMethod(aInstance.MyEvent); //THIS IS where i dont know
what to do !!!!!!!!!
}
}
//This class do some work for the worker-thread and is supposed to notify
the listeners (in MyEvent) about the ongoing work.
public class Third
{
public void AMethod(EventHandler<EventArgs> callback)
{
if (callback != null)
callback(this, new EventArgs());
}
}
My problem is in class Second. How do i pass the event (in th.AMethod())
??
Is this what you mean?
public class First
{
public event EventHandler<EventArgs> MyEvent;
public void OnMyEvent(object sender, EventArgs args)
{
if(this.MyEvent != null)
this.MyEvent(sender, args);
}
}
public class Second
{
public void Method(First aInstance)
{
Third th = new Third();
th.AMethod(aInstance.OnMyEvent);
}
}
public class Third
{
public void AMethod(EventHandler<EventArgs> callback)
{
if(callback != null)
callback(this, new EventArgs());
}
}
PS
.
- References:
- Delegates/events
- From: Peter Larsen []
- Delegates/events
- Prev by Date: Re: TextWriter fails on Close() call in destructor
- Next by Date: Re: TextWriter fails on Close() call in destructor
- Previous by thread: Re: Delegates/events
- Next by thread: RE: Delegates/events
- Index(es):
Relevant Pages
|