Go Premium for a chance to win a PS4. Enter to Win


UI + Threads

Posted on 2004-10-27
Medium Priority
Last Modified: 2011-09-20

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.
Question by:bhanley9681
1 Comment

Accepted Solution

Razzie_ earned 1200 total points
ID: 12423681
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:) :




Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question