Safely close UI threads when program exit
-
hi, I have a list of UI threads that need to be close and clean up properly when user click "Exit" in the main GUI. How to do it? Here's what i've tried: CFrameWnd::OnClose() { for (i=0;i < my_number_of_thread; i++) { pThead[i]->EndThreadSafely(); } ClearThreadList(); } But my application crash in the end, debugging show an error at the AfxEndThread() that I call at the end of CMyThread::EndThreadSafely()
-
hi, I have a list of UI threads that need to be close and clean up properly when user click "Exit" in the main GUI. How to do it? Here's what i've tried: CFrameWnd::OnClose() { for (i=0;i < my_number_of_thread; i++) { pThead[i]->EndThreadSafely(); } ClearThreadList(); } But my application crash in the end, debugging show an error at the AfxEndThread() that I call at the end of CMyThread::EndThreadSafely()
You end UI-threads by posting a WM_QUIT message to the thread. After you've posted the message you may wait for the thread to terminate by waiting on thread handle with e.g.
::WaitForSingleObject()
in your main thread. AvoidAfxEndThread()
, simply let the thread exit from it's controlling function which is the message pump in the UI-thread case. For more info read here[^] and here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
hi, I have a list of UI threads that need to be close and clean up properly when user click "Exit" in the main GUI. How to do it? Here's what i've tried: CFrameWnd::OnClose() { for (i=0;i < my_number_of_thread; i++) { pThead[i]->EndThreadSafely(); } ClearThreadList(); } But my application crash in the end, debugging show an error at the AfxEndThread() that I call at the end of CMyThread::EndThreadSafely()
set CWinThread::m_bAutoDelete member to true!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You