Order of event handler execution

If I set up multiple event handlers, like so:

_webservice.RetrieveDataCompleted += ProcessData1;
_webservice.RetrieveDataCompleted += ProcessData2;

what order are the handlers run when the event RetrieveDataCompleted is fired? Are they run in the same thread and sequentially in the order that are registered?


Currently, they are executed in the order they are registered. However, this is an implementation detail, and I would not rely on this behavior staying the same in future versions, since it is not required by specifications.


The invocation list of a delegate is an ordered set of delegates in which each element of the list invokes exactly one of the methods invoked by the delegate. An invocation list can contain duplicate methods. During an invocation, a delegate invokes methods in the order in which they appear in the invocation list .

From here: Delegate Class


The order is arbitrary. You cannot rely on the handlers being executed in any particular order from one invocation to the next.

Edit: And also - unless this is just out of curiosity - the fact that you need to know is indicative of a serious design problem.

链接地址: http://www.djcxy.com/p/68062.html

上一篇: C#,事件处理程序和线程

下一篇: 事件处理程序执行顺序