EventHandler is just a delegate--which provides the functinality of an
object-oriented function pointer.  If you want to delegate to the same
method using the same delegate allocation, there's no problem with that.
The only state kept by the delegate is the method to call; the rest of the
state is passed upon invocation.

GC will deal with de-allocation when both references are not needed
anymore.

http://www.peterRitchie.com/

On Tue, 12 Jul 2005 10:59:42 +0100, Andrew Marshall
<[EMAIL PROTECTED]> wrote:

>Hi all,
>
>Say I have two objects capable of sending events, and an event handler.
>
>I could do this...
>1.
>////////////////////////////////////////////////////////////////
>
>public void objectHandler( object sender, EventArgs args )
>{
>    ...do some stuff...
>}
>
>{
>  ...
>  object1.myevent += new EventHandler( objectHandler );
>  object2.myevent += new EventHandler( objectHandler );
>  ...
>}
>
>or this...
>2.
>///////////////////////////////////////////////////////////////////
>
>public void objectHandler( object sender, EventArgs args )
>{
>    ...do some stuff with sender...
>}
>
>{
>  ...
>  EventHandler myEventHandler = new EventHandler( objectHandler );
>  object1.myevent += myEventHandler
>  object2.myevent += myEventHandler
>  ...
>}
>
>/////////////////////////////////////////////////////////////////////////
>
>Is there any difference? 2. Seems more sensible to me, and it appears to
>work, but being a bit hazy on events in .NET I was wondering if there
might
>be issues I'm not aware of.
>

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to