UI + Threads


I just found out that I wasn't updating my GUI correctly w/ my worker threads (just doing it directly - never had a problem, but I assume race conditions could develop pretty easily).  Anyways, I know I have to use Control.Invoke stuff.

My question is: does the same go for opening a new window?  That is, if I want to open a new Form - think modeless dialog rather than some MDI thing - Do I have to do it from the main thread for it to persist after my thread dies?

In addition: For my own understanding, how is this actually working under the hood?  When you start a new project, don't you have a GUI thread that handles UI events as well as a main worker thread?  Why can you update the GUI w/ the main worker thread and now side threads?  Or is there just one thread?  I'm kinda confused...

When I created a Form from a worker thread, the form only lasted while the worker thread lasted - how does that fit in w/ the above?  The variable w/ a handle to the form wasn't getting disposed or anything.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

From what I know (don't shoot me if anything I say is not true:), if you start a new project, there is a UI Thread that resides in the STA (Single Threaded Apartement), and all UI related stuff should be called from the main thread, not directly from other threads.
Modeless Forms run in their own thread. But I think that if the thread that created it dies, your modeless form will die too.

The following 2 links are interesting reads about it (and will surely explain things much better:) :




Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.