Solved

UI + Threads

Posted on 2004-10-27
226 Views
Last Modified: 2011-09-20
Hi,

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

    Accepted Solution

    by:
    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:) :

    http://blogs.msdn.com/cbrumme/archive/2004/02/02/66219.aspx
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrconthreadingsupportinoffice.asp

    HTH,

    Razzie
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now