I've got a form that creates a couple of disposable resources in its constructor that I need to dispose of. However, the C# form designer already produces a Dispose() method in the Designer.cs file that doesn't appear to have any type of user hook in it. So I'm at a loss as to how I'm supposed to implement the typical IDisposable
pattern.
This form is occasionally created but never shown, so using the Close event won't help.
The objects in question are not IComponents
, so I can't just add them to this.components
.
Where can I put this clean-up code and be sure it will run when the form is disposed?