Threading newbie: Can I have two threading both runing its own GUI?

Say, I have one main thread showing GUIs, and another created thread, which also want to show forms. These forms are only created and accessed in the second thread. Can it be possible If so, How it can be done

Sample code snippet: (the effect is Form2 just falsh and be off, the question is how can I keep the Form2 be on the window in the second thread)

Main() {} 
Button_Click()
{
Thread ChildThread=new Thread(new ThreadStart(ShowAForm));
ChildThread.Start();
}

ShowAForm()
{
Form2 f2=new Form2();
f2.Show();
}

Thanks very much!


Answer this question

Threading newbie: Can I have two threading both runing its own GUI?

  • Kardath

    Thanks. It works.

  • prawin

    Hi

    In the second thread call Application.Run instead of Form.Show.



    private void button1_Click (object sender, EventArgs e)
    {
       
    Thread thread = new Thread (new ThreadStart (ThreadFunc));
       thread.Start ();
    }

    private void ThreadFunc ()
    {
       
    Application.Run (new Form2 ());
    }

     



    Cheers!
    Michael



  • Threading newbie: Can I have two threading both runing its own GUI?