Context
I am working with a Winforms application (.NET 3.5 SP1), which has a workspace concept that can contain n number of panels. Each panel (obtained from Panel) has the form:
.-----------------------.
| Workspace |
| .--------. .--------. |
|| Panel1 | | Panel2 | |
|| .-----. | | .-----. | |
||| View1 | | || View2 | | |
|| '-----' | | '-----' | |
| '--------' '--------' |
'-----------------------'
All panels are added to the collection this.Controlsof the Workspace class (which is derived from UltraTabPageControlthe Infragistics GUI control). Each view is added to Controlstheir parent's collection . Therefore, when Disposecalled in the workspace, panels and views are automatically deleted, which is quite expected and desirable.
We have another concept called a ViewManager. It tracks all the controls Viewin the workspace and is responsible for maintaining one “main” view. Whenever created View, it registers with this manager. This adds Viewto the list and then runs some logic to define a new “main” view, and then calls a method Synchronize()for each view.
, , View.Dispose(), ViewManager. View , , .
, Panel, . , Dispose, :
protected override void Dispose(bool disposing)
{
var theSpecialPanel = GetSpecialPanel();
if (theSpecialPanel != null)
{
theSpecialPanel.Dispose();
}
base.Dispose(disposing);
}
, theSpecialPanel. -, Synchronize() View, .
"InvalidComObjectException: COM-, RCW, ."
? , - ?