Consider the code using GetInvocationList :
foreach (var handler in theEvent.GetInvocationList().Cast<TheEventHandler>()) { // handler is then of the TheEventHandler type try { handler(sender, ...); } catch (Exception ex) { // uck } }
This is my old approach, the newer approach that I prefer is higher because it calls for binding, including using out / ref parameters (if desired).
foreach (var singleDelegate in theEvent.GetInvocationList()) { try { singleDelgate.DynamicInvoke(new object[] { sender, eventArg }); } catch (Exception ex) {
which individually calls each delegate that would be called using
theEvent.Invoke(sender, eventArg)
Happy coding.
Remember to make a standard copy of null-guard copy'n'check (and possibly block) when working with events.
user166390
source share