PC Review


Reply
Thread Tools Rate Thread

Delegation, Event-Listeners

 
 
=?Utf-8?B?bWF0aG9u?=
Guest
Posts: n/a
 
      25th Oct 2005
Hello,

could anybody explain me the advantages and disadvantages of delegation and
the advantages and disadvantages using event-listeners? - both related to the
treatment of events.

thanks in advance

regards

mat
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
Guest
Posts: n/a
 
      26th Oct 2005
In both cases, you have the definition, the wiring and the handler.
Delegates, however, are a bit more flexible. If you do not require the
flexibility, or feel you ever will, stick with events. That would be my
suggestion. I am not sure I can list a pro/con for each as they would be
pretty much the same list.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


"mathon" wrote:

> Hello,
>
> could anybody explain me the advantages and disadvantages of delegation and
> the advantages and disadvantages using event-listeners? - both related to the
> treatment of events.
>
> thanks in advance
>
> regards
>
> mat

 
Reply With Quote
 
Richard Grimes
Guest
Posts: n/a
 
      27th Oct 2005
mathon wrote:
> could anybody explain me the advantages and disadvantages of
> delegation and the advantages and disadvantages using
> event-listeners? - both related to the treatment of events.


Delegates are managed function pointer objects. Events are simply
metadata. When you add a delegate to a class you have the responsibility
to also add code to initialize the delegate and to invoke it in a thread
safe way (and only if it is initialized). If you add an event to your
class the compiler will add the delegate field, the methods to
initialize it and the code to invoke it. Since the (Microsoft) compiler
adds this stuff, it will add this code using set conventions so that
other code that uses the event will know exactly how to use it.

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Oct 2005
Richard Grimes <(E-Mail Removed)> wrote:
> mathon wrote:
> > could anybody explain me the advantages and disadvantages of
> > delegation and the advantages and disadvantages using
> > event-listeners? - both related to the treatment of events.

>
> Delegates are managed function pointer objects. Events are simply
> metadata. When you add a delegate to a class you have the responsibility
> to also add code to initialize the delegate and to invoke it in a thread
> safe way (and only if it is initialized). If you add an event to your
> class the compiler will add the delegate field, the methods to
> initialize it and the code to invoke it. Since the (Microsoft) compiler
> adds this stuff, it will add this code using set conventions so that
> other code that uses the event will know exactly how to use it.


Note that the compiler only adds the delegate field if you add a
"field-like" event. If you provide your own add/remove methods, the
compiler doesn't add any extra bits. The event itself is distinct from
the delegate - various classes in the framework don't use the "one
delegate field per event" model, having a map of them, for instance.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
?? Changing Event Listeners But Allowing GC ?? Tom Baxter Microsoft Dot NET Framework Forms 0 11th Sep 2008 05:10 PM
Delegation, Event-Listeners =?Utf-8?B?bWF0aG9u?= Microsoft Dot NET 1 26th Oct 2005 07:49 AM
Event Listeners on a protected chart James Martin Microsoft Excel Programming 1 5th Aug 2005 12:45 PM
Event listeners? Deena Microsoft C# .NET 4 21st Jul 2004 02:51 PM
How to check for event listeners? Max Microsoft VB .NET 9 30th Mar 2004 11:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:10 AM.