Solved

Pumping messages during Thread.Join(myTimeout)

Posted on 2008-10-10
1
458 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 85

Accepted Solution

by:
Mike Tomlinson earned 125 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

16 Experts available now in Live!

Get 1:1 Help Now