I am puzzled by this simple task, which I do again and again.
I have an array of child forms. The array is launched in another form constructor:
frmChildren = new ChildGUI[20];
When a user requests a child form, I do this:
if (frmChildren[nb] == null) { frmChildren[nb] = new ChildGUI(); frmChildren[nb].MdiParent = this.MdiParent; } frmChildren[nb].Show();
While this is working . In the background, I can upload new content for these forms. When the download is complete, I fire the ChildChange event. Here it stops working. I just want to close / hide any forms, and then restore the new set -frmChildren = new ChildGUI [20]; - here is one of many tests:
for (int i = 0; i < frmChildren.Length;i++ ) { if (frmChildren[i] != null) { //frmChildren[i].BeginInvoke(new EventHandler(delegate //{ frmChildren[i].Close(); //})); } } frmChildren= new ChildGUI[20];
I get a Cross Thread exception in .Close (). Notice that I already tried to make a call, but at the same time for some reason bypasses the value! = Null. I think this may have something to do with the garbage collector. Does anyone have an entrance?
Roast source share