Follow @RoyOsherove on Twitter

Defensive event publishing, a different approach

Eric has posted a nice example of invoking "safe events" without using the threadpool, as was mentioned in my own article here. You should definitely go read his post and see his code, since it's different way of looking at things, and it's always good to see other perspectives.
Personally, I find it a bit more cumbersome, but then again, it lets you have a little more control on your events, and is more fit for situations which are not pure "fire and forget".
 
"Several months ago, Roy Osherove posted a discussion of Defensive Event Publishing in .Net that discussed various problems with the "normal" methods of event publishing and raising in .Net. The naive programmer merely calls MyEvent(sender, eventArgs), never suspecting the minefield into which he or she is blithely strolling. Roy's post suggests several progressively more cautious methods of raising events to protect oneself against "bad" clients. At the time I commented that further improvements could be made, specifically to both avoid using Threadpool threads and to detect which callers are bad. I thought I'd finally get around to explaining what I meant and actually providing a solution I've used in the past."

TimedLock class: helping find and avoid deadlocks in your multithreaded code

Solving Binary serialization versioning conflicts - The HashTable problem