// JP opened flex table

Click to See Complete Forum and Search --> : How to force ExitInstance() to be executed?


s_k
May 31st, 2003, 05:15 AM
I have MFC application, in which I create one more CWinThread object, handled in separate thread, using AfxBeginThread. But when my whole app finishes, ExitInstance() of this user-interface thread is not executed. I need it to perform some cleanup..

Can somebody help me?

Thanks Standa.

Cait
June 1st, 2003, 04:19 AM
I may be totally wrong but i think you need to PostMessage(WM_CLOSE) or (WM_QUIT) to the thread.

s_k
June 1st, 2003, 04:44 AM
You're right, I've already found it out.
I was wrongly supposing that during termination of main process all children threads must be sent WM_QUIT message automatically...

lsvedin
November 30th, 2004, 03:39 PM
I realize this is an old thread, but I have the same probem and I am sending the thread WM_QUIT.

The thread is a socket thread waiting for data and when the application closes, I send the thread the following message:

m_pNetWriteThread->PostThreadMessage(WM_QUIT, NULL, NULL);
::WaitForSingleObject(m_pNetWriteThread->m_hThread, INFINITE);

There is a breakpoint in the beginning of ExitInstance of the thread, and in debug, it never breaks there and it hangs up on the WaitForSingleObject.

Any suggestions?

Andreas Masur
November 30th, 2004, 03:50 PM
Are you using blocking sockets? I assume since you are mentioning that you are waiting for data...so, the 'recv()' does block and thus your thread will ot process its message queue...

//JP added flex table