Form in thread

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Hi,

I am writing a C# win form application that show 3 different winform dialog
and i wanf that every form dialog will run in a differnt thread, how can i
do that?
How can i create or show a win form in differnt thread?, can you send me an
example?

Thanks.
 
Dave said:
I am writing a C# win form application that show 3 different winform dialog
and i wanf that every form dialog will run in a differnt thread, how can i
do that?
How can i create or show a win form in differnt thread?, can you send me an
example?

You can't do that. The only thing you can do is create all your forms on
the UI thread and later update them as needed from other threads - but
you have to be very careful if you do this, because direct calls to the
controls that were created on the UI thread are not allowed.

There's a blog article by Justin Rogers that I like to recommend, it
explains a lot of the background of this topic:

http://weblogs.asp.net/justin_rogers/articles/126345.aspx

Hope this helps!


Oliver Sturm
 
Dave said:
Hi,

I am writing a C# win form application that show 3 different winform dialog
and i wanf that every form dialog will run in a differnt thread, how can i
do that?
How can i create or show a win form in differnt thread?, can you send me an
example?

Thanks.


You can do so by creating additional message loop in the new thread by
calling
"Application.Run(formObj)".


Firstly, create a new thread,

....
new Thread(new ThreadStart(NewMessageLoopFun));
....

Secondly, in the new thread, create a Form and call "Application.Run"

void NewMessageLoopFun()
{
....
FormX f=new FormX(..);
Application.Run(f)
....
}
 
Back
Top