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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.