安全事件
public static class EventHandlerExtensions { public static void SafeInvoke<T>(this EventHandler<T> evt, object sender, T e) where T : EventArgs { if (evt != null) { evt(sender, e); } } }
Using that method, you can invoke the events like this: protected void OnSomeEvent(EventArgs e) { SomeEvent.SafeInvoke(this, e); }