MDI Children on their own thread?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Okay, I have several Forms. I call a factory method which creates a new
thread, and in the threadstart I create a new Form (newForm) and call
"Application.Run(newForm)". This works fine. However, assigning the form to
the MDIParent causes a threading violation:

Form FindParent()
{ foreach (Form frm in Application.Forms)
if (frm.IsMdiContainer) return frm;
}

void AddClientForm( Form newForm)
{
Form frm = FindParent();
newForm.MDIParent = frm; // exception!
}
 
Kenneth Davis said:
Okay, I have several Forms. I call a factory method which creates a new
thread, and in the threadstart I create a new Form (newForm) and call
"Application.Run(newForm)". This works fine. However, assigning the form
to
the MDIParent causes a threading violation:

Create the forms in the main UI thread. You cannot add controls/forms to a
form created by another thread.
 
Back
Top