How to show a form in new thread ?

  • Thread starter Thread starter cyshao
  • Start date Start date
C

cyshao

How to show a form in new thread ?


My form will be shown when main form doing a large process.

Could you tell me how to create and control this new form?

Thanks

Charles Shao :-)
 
The this.mymethod is the method that will launch your new form. The form is
launched in a separeate thread.

System.Threading.Thread t = new System.Threading.Thread(new
System.Threading.ThreadStart(this.mymethod));
t.Start();
 
All gui should be done by the main thread (i.e the thread that start
your application) to access any gui from another thread you have to
use one of the invoke methods.
 
QWERTY said:
All gui should be done by the main thread (i.e the thread that start
your application) to access any gui from another thread you have to
use one of the invoke methods.

This is a serious misconseption, you can have as much GUI threads as you
like, as long as you respect the GUI threading rules imposed by Windows,
that is you need to pump messages and you shouldn't touch the windows
elements directly from other threads. When drag and drop support is needed
or when you host ActiveX controls on the forms, make sure your thread runs
in a STA.

Willy.
 
private void showForm() {
Form form1= new Form();
form1.show();
}
Thread sf= new Thread(new ThreadStart(showForm);
sf.Start();
 
Back
Top