MFC and threads
Greetings,
I am running into a problem when trying to pause a thread in MFC based
application. This is my first time using user defined Events for
synchronization. The scenario is like this. Code executes in a worker
thread and based on some conditions thread launches another new dialog
window. That window displays some message to user ie, Hello There! in
an Edit control. I provide a Resume button on the bottom of that
message Window so that user can continue after reading the message and
the worker thread should continue from where it left off. This is the
code for that Resume button.
void DUMMY::OnResume()
{
// TODO: Add your control notification handler code here
CWorkerDlg dlg; << Primary window which launched Dummy dialog
Window
dlg.paused = FALSE; << paused defined in CWorkerDlg as BOOL
// sets the state of the specified event object to signaled.
if ( ! ::SetEvent(dlg.hEvnt) )
{
AfxMessageBox("SetEvent not sucessful");
}
// User is done reading the message-Close the window
EndDialog(0);
}
First problem, my SetEvent always reports failure. Why? Also, I get
debug asseration failure windows. When it reaches the last line,
EndDialog(0) it pops up Debug Assertion Failure window. What am I
doing wrong? Thanks for help.