In .Net the Component class exposes a Disposed event. It also provides a protected member OnDispose(bool disposing).
What is the best practice for a custom component that extends Component? Override OnDispose(bool) or attach an event handler to Disposed on construction?
My feeling is that one should override OnDispose(bool) and seal the class.
Thoughts?
Typically events are used by consumers so that they can be notified when events occur. If you’re extending the Type and need to clean up resources you should override Dispose(bool disposing)
Spence is partly right about the Event handler, multiple events can be assigned but the issue is that you can’t guarantee the order in which the Events are handled.
Sealing the class often depends on what you’re designing.
The FxCop rule also has some good info: http://msdn.microsoft.com/en-us/library/ms244737(VS.80).aspx