Solved

Pumping messages during Thread.Join(myTimeout)

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Disable Security Alert  popup in Winforms  embedded webbrowser. 1 57
VB.Net Tranfer data between to VB.Net apps 8 40
.NET 2008 VB and C# 6 39
Help with error in Query 2 31
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)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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