• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

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.
1 Solution
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now