Monday, September 14, 2009

Cometh The Gu

This should be old news to most readers (it was announced all of 3 days ago!), but bears re-posting.

Scott Guthrie is presenting in Manchester
on 29th September!

Why haven’t you registered already?


Wednesday, September 09, 2009

Wednesday Quickie: Forcing event un-subscription

This is another really simple and obvious code snippet, but one well worth remembering – posted this morning by Fabrice MARGUERIE.

The crux is that event subscriptions can cause memory leaks – so ensuring they are un-subscribed is essential. The code snippet is designed to be used in the Dispose or Cleanup method on the publishing object, and forcibly disconnects any subscribers just before the publishing object is disposed.

if (SomeEvent != null)
foreach (EventHandler handler in SomeEvent.GetInvocationList())
SomeEvent -= handler;

Simple. Clean. Elegant. Use it!

Force your subscribers away: