|
For forced exit, you can use endThread. This function is also used in the thread. However, this method is not recommended.
Generally use TerminateThread ();
Here are two functions for your reference:
void MyThread :: WaitForThreadToTerminate (HANDLE hThread) // Wait for the thread to terminate
{
DWORD dwRet;
do
{
dwRet = :: MsgWaitForMultipleObjects (1,&hThread, FALSE,
INFINITE, QS_ALLINPUT);
if (dwRet! = WAIT_OBJECT_0)
{
PeekMessageLoop ();
}
} while ((dwRet! = WAIT_OBJECT_0)&&(dwRet! = WAIT_FAILED));
}
void MyThread :: PeekMessageLoop ()
{
MSG msg;
while (PeekMessage (&msg, NULL, NULL, NULL, PM_REMOVE))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
MyThread :: ~ MyThread ()
{
EndThread_Proc ();
if (bEndTDde)
{
WaitForThreadToTerminate (pMyThread-> m_hThread);
}
}
void MyThread :: EndThread_Proc ()
{
bEndTDde = True;
}
CWinThread * pMyThread;
BOOL bEndTDde;
I hope useful to you. |
|