How to effectively wait for a thread to complete in a dialog class?
-
I have a MFC dialog application with multiple child dialogs inside a main dialog and then a few normal classes controlling a camera and other hardware. I have a thread in camera class that is always active and waits for couple of events to do further processing within the thread. One of the events is a manual event and the other one auto event. The manual event keeps running as soon as the application is launched. But when the user pressed a button on one of the child dialogs, I would like to Set the auto event, for this within the button even handler of the child dialog, I call ResetEvent() on the camera thread manual event, wait for sometime using ::WaitForSingleObject command and then call SetEvent() on the camera thread auto event. But not matter how much time I wait in the even thandler, the SetEvent executes only when I am out of the button's event handler. Ideally I would like to wait for another event (using WaitForSingleObject) that is Set by the camera thread after its done with the autoevent process.
// All events are global handles
//Camera class
//thread function
{
event[1] = manual event;
event[2] = auto event;
event[3] = auto event done event;switch(Waitformultipleobject(event[3]))
{
case manual event:
// keep doing some process until the manual event is reset
break;
case auto event:
// perform the process
Set (auto event done event);
break;}
}
}//Child dialog class
button event handler
{
Reset(manual event)
Set(auto event)
WaitForSingleObject(auto event done event, ms);
}Any tips/suggestions on how to achieve this?
PKNT