Hello!
If I have n event handlers will these always be called in the same sequence
as they subscribe to the event
//Tony
"Jon Skeet [C# MVP]" <sk***@pobox.comskrev i meddelandet
news:b7**********************************@z6g2000p re.googlegroups.com...
On Aug 7, 7:40 am, "Tony Johansson" <johansson.anders...@telia.com>
wrote:
I know it's possible to have several event handler for a single event but
I
can't see any point using several event handler for this.
I'm probably wrong so can anybody tell me what advantage it might give
using
several event handler for a single event.
Suppose two completely separate pieces of code both want to react to a
button being clicked. One might be performing the normal user
interface interaction, and the other might be logging all UI
interaction for usability reasons. How would you do that without
multiple event handlers?
Another example: the AppDomain.DomainUnloaded event. How can you
possibly be sure that only one piece of code will be interested in the
timing of AppDomain unloading?
Another example: Marc Gravell and I developed "Push LINQ" where data
is effectively pushed through predicates etc rather than pulled.
Handlers are registered to say they're interested in seeing data being
produced (and the "end of data" event). Using multiple event handlers
attached to the same event, you can compute several aggregates on the
same stream of data incredibly easily.
Having multiple event handlers doesn't come up *very* often, but it's
handy to be able to do it, and the way that delegates work make it
simple to achieve.
Jon