amakalski
asked on
When MFC application terminates
I call PostQuitMessage to main UI thread of MFC, I have other threads in the app.
Will MFC app terminate or it will wait until all threads terminate ?
Will MFC app terminate or it will wait until all threads terminate ?
ASKER
AlexFM,
Do you say that after posting QUIT msg to main UI thread, app will be terminated and other threads will be killed? Is that right?
Do you say that after posting QUIT msg to main UI thread, app will be terminated and other threads will be killed? Is that right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I apologize for providing wrong information. PostQuitMessage doesn't terminate all threads in process. It terminates only UI thread to which it posted. ExitProcess and TerminateProcess functions terminate process and all it's threads.
In any case, all worker threads should be stopped before exit using the way shown in my first post.
In any case, all worker threads should be stopped before exit using the way shown in my first post.
SetEvent(hStopEvent); // ask thread to exit
WaitForSingleObject(hThrea
Thread function should check stop event periodically:
while (...) // some loop
{
// do something
if ( WaitForSingleObject(hStopE
break;
}
// clean-up and return