Problem with WaitForMultipleObjects
Dear all GURUs,
I'm facing a problem with my WaitForMultipleObjects function.
I'm writing a thread to wait for 3 result using event.
When getting all the result, then only i proceed to next step.
I have a start button to trigger the thread start and stop.
After the thread start, my problem will call WaitForMultipleObjects to wait for all the result complete.
If i press stop now, the WaitForMultipleObjects seem to be on going. it did not stop when i press stop.
How can i stop the WaitForMultipleObjects once i stop the thread? if not after the timing, it will proceed to next step.
Quote:
void CMyFunction::Run()
{
DWORD dwEvent=0;
while(m_bStart)
{
dwEvent = WaitForMultipleObjects(
3, // number of objects in array
m_hEvent, // array of objects
TRUE, // wait for any object
5000); // five-second wait
//proceed to next step
AfxMessageBox("Done");
};
}
Thanks.
Re: Problem with WaitForMultipleObjects
Quote:
Originally Posted by
VbEndUser
If i press stop now, the WaitForMultipleObjects seem to be on going. it did not stop when i press stop.
May be you simply didn't process the Stop button? Because your main thread was blocked?
Try using MsgWaitForMultipleObjects() instead.
Re: Problem with WaitForMultipleObjects
Another way would be to not use WFMO at all.
Instead let your threads PostMessage a user defined message to the main GUI thread notifying that the thread is about to stop (exit, and so on...)