0

Hi,
I have a MDIParent and forms that i want to show as child. But because each individual child performs heavy tasks I want each child to have it's own thread.
here's what I am trying to do...

void showStartPage()
{
    Form1 p = new Form1();
    p.MdiParent = this;
    p.Show();
}

private void ShowNewForm(object sender, EventArgs e)
{
    Thread t = new Thread(new ThreadStart(showForm));
    t.SetApartmentState(ApartmentState.STA);
    t.Start();
}

Here showForm is the function that needs to be started in a new thread so that i can start a new form. But i get an exception when using the line
p.MdiParent = this;
It says.."Cross-thread operation not valid: Control 'MDIParent1' accessed from a thread other than the thread it was created on."

I want to know how i can create new forms in a new thread.
Any help is greatly appreciated
Thank you

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Momerath
0

Only one thread in your program can actually interact with the GUI, and that's the problem you are seeing.

If your child forms have heavy processing to do, you can spawn threads to handle that processing and when the thread is done, update the GUI.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.