I have this piece of code in a secondary stream:
DWORD result = WaitForSingleObject(myhandle,10000);
if(result == WAIT_OBJECT_0){
AfxMessageBox(_T(...));
}
else if(result == WAIT_TIMEOUT){
AfxMessageBox(_T("Timeout"));
}
Sometimes, not always, a timeout will be called almost immediately after calling WaitForSingleObject (not even a delay of 1 s).
Am I doing something wrong? Any suggestions for more stable alternatives?
EDIT:
myhandle is created inside the class constructor as:
myhandle = CreateEvent(NULL,FALSE,FALSE,_T("myhandle"));
it will be called by another function:
SetEvent(myhandle);
The fact is that this works when I do a SetEvent, the problem is that it sometimes expires as soon as WaitForSingleObject is called, although it should wait 10 seconds.
Smash source
share