Friday, January 4, 2008

Implementing a custom Dispose for a form or usercontrol

Have you ever wanted to implement a custom dispose method for a usercontrol or a form. Trying to override protected void dispose(bool disposing) learns that the designer generated file (mycontrol.designer.cs) already implements this override.

Mark Seemann wrote an intersting approach for dealing with this situation in his blog. It makes use of an Disposer component. A new instance will be created with a reference to a method implementing the custom dispose functionality. This instance is being added to the components collection. When the components get disposed, the this Disposer calls the delegate function with custom dispose logic. That's it.

Thanks Mark for this article.

No comments: