|
-
January 17th, 2012, 10:17 AM
#1
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.
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.
-
January 17th, 2012, 10:28 AM
#2
Re: Problem with WaitForMultipleObjects
 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.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
January 17th, 2012, 12:26 PM
#3
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...)
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|