You have 10 event subscribers in your application. When you trigger an event, do subscribers receive a notification synchronously or asynchronously?
It depends on how the publisher "triggers" the event. In a typical case (for example, a C # field event), the handlers are simply members of the call list of the multicast delegate. Invoking an βeventβ is equivalent to invoking a support delegate, which, in turn, is morally equivalent to invoking each of its individual members in sequence. Therefore, once it was possible to call a call, for example:
MyEvent(this, myEventArgs);
looks like:
foreach(EventHandler handler in myEventDelegate.GetInvocationList()) handler(this, myEventArgs);
This is just a sequence of delegate calls: subscribers are notified synchronously . Of course, the publisher can select the event in any way that he likes, so he does not need to do this - he can very well use the thread pool (QUWI / BeginInvoke) or any other mechanism that creates asynchronous notifications.
You have 10 event subscribers in your application. Now one event for the handler has bad code, and it throws an exception. Do nine more event handlers go on?
Again, it depends. In a typical (aforementioned) case, the answer is no , because exceptions are not handled based on each subscriber. If the handler throws, the rest of the "foreach" is abandoned. Of course, there is nothing to stop the publisher from wrapping a call to each handler in a try-catch (ignore) block or using any other mechanism to ensure that all handlers are called.
Ani
source share