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 ?
Who is Participating?
AlexFMConnect With a Mentor Commented:
All threads will be terminated. However, good programming style requires to stop all worker threads before exit. Every worker thread should have stop event associated with it. When main thread needs to stop the worker thread, it executes the following code:

SetEvent(hStopEvent);   // ask thread to exit
WaitForSingleObject(hThread, INFINITE);  // wait when thread really exits

Thread function should check stop event periodically:

while (...)   // some loop
    // do something

    if ( WaitForSingleObject(hStopEvent, 0) == WAIT_OBJECT_0 )  // stopped ?

// clean-up and return

amakalskiAuthor Commented:
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?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.