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

x
?
Solved

Pumping messages during Thread.Join(myTimeout)

Posted on 2008-10-10
1
Medium Priority
?
471 Views
Last Modified: 2013-12-17
Hi everybody,

I use a thread to wait until an event occurs.
I create and lauunch the thread, than wait until the threads ends or a timeout is reached.
The problem is (I think), that during Thread.Join(myTimeout) there is no messages pumping, and so no event can be catched !
How could I pump messages ?
Or should I use anything else that Thread.Join method ?

Thank you very much,
Vincent
....
Thread WaitUntilEventThread = new Thread(new ThreadStart(WaitEventService));
WaitUntilEventThread.Start();
WaitUntilEventThread.Join(myTimeout);
}
 
private void WaitEventService()
{
     while(!isMacroComplete)
     {
          Thread.Sleep(500);
     }
}
 
private void Pathway_MacroComplete(object sender, MyLib.MyEvent eventArgs)
{
      isMacroComplete = true;   
}

Open in new window

0
Comment
Question by:vinceTrace
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 22688126
Right...there is no point in making a new thread if you are just going to Join() them...   =\

If you really want to force the pumping of messages then use "Application.DoEvents()".

*** BUT *** if you do this then there is really no need for the separate thread is there?

Just use a polling loop to look for the toggling of your flag:

    // some code
    while(!isMacroComplete)
     {
          Thread.Sleep(100); // use a smaller number than 500 or your UI will be sluggish!
          Application.DoEvents();
     }
     // some more code that needs to run after "isMacroComplete" toggles

If you really want to use a different thread that doesn't require DoEvents() then encapsulate the while loop in a class that raises an EVENT when the flag is toggled.  This would require a change in your code methodology though as you would be moving from linear code to event driven code.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Loops Section Overview
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