I was also getting the same InvalidOperationException when I used to close my forms. My solution was to make sure that all my controls got disposed in the Dispose method of my UserControls. Here's the code :
Code:
protected override void Dispose(bool disposing)
{
if (disposing)
{
foreach (Control control in this.Controls)
{
IDisposable disposable = control as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
}
Bookmarks