Given this implementation, yes, they will always be called in that order.
If the event does use some weird and wonderful way to process the subscription, it can do different things, but the โnormalโ implementations will do the right thing.
To be clear, subscribing to an event handler means only accessing the corresponding โaddedโ part of the event. If the event handles this, doing something like:
myHandler += value;
which translates to
myHandler = Delegate.Combine(myHandler, value);
and Delegate.Combine guarantees the order. However, if you had such an event:
private LinkedList<EventHandler> eventHandlers = new LinkedList<EventHandler>; public event EventHandler Foo { add { eventHandlers.AddFirst(value); } remove {
and then fired the event by doing something like:
foreach (EventHandler handler in eventHandlers) { handler(this, EventArgs.Empty); }
then the handlers will be called in the reverse order.
Summary For all reasonable events, you can rely on ordering. Theoretically, events can do what they like, but I have never seen events that do not support the proper order.
Jon Skeet Dec 17 '08 at 12:41 2008-12-17 12:41
source share