Friday 26 August 2011

Threadsafe Events in .Net

Usually the event pattern used by C# devs would be something long these lines:

When actually this provides for a cleaner threadsafe implementation:

Thanks to Rob Eisenberg for the suggestion!

Remember the event keyword is just a modifier for a delegate declaration that allows it to be included in an interface, constraints it invocation from within the class that declares it, provides it with a pair of customisable accessors (add and remove) and forces the signature of the delegate (Object sender, EventArgs e).

No comments:

Post a Comment