Hi,

Could someone explain to me why this doesn't work? (VS 7.1, .NET 1.1)

Thread A:
Application.Run();

Thread B:
myForm.Show();

If I run both on the same thread it works.

I thought that it was enough to have a message loop running on any thread
in the application to make forms work, but apparently not. Why?

If I change the code in thread A to Application.Run(myForm); the form works.
Why? I thought the only difference would be that the message loop would now
exit when the form closes.

If I change the code in thread B to myForm.ShowDialog(); the form also
works. Why?


--
Patrik Rådman
patrik at iki dot fi
http://www.iki.fi/patrik/

Re: Message loop question by Mattias

Mattias
Tue Oct 18 10:43:33 CDT 2005

Patrik,

>I thought that it was enough to have a message loop running on any thread
>in the application to make forms work, but apparently not. Why?

Just like any other loop, a message loop runs on a specific thread and
doesn't affect other threads running. So you need one for each thread
you want to display UI on.


>If I change the code in thread A to Application.Run(myForm); the form works.
>Why? I thought the only difference would be that the message loop would now
>exit when the form closes.

Then myForm is shown from the UI thread A.


>If I change the code in thread B to myForm.ShowDialog(); the form also
>works. Why?

ShowDialog creates its own message loop for the modal window.


Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.