MDI Children on their own thread?

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!
}
 
H

Herfried K. Wagner [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top