|
发表于 2020-2-16 19:00:01
|
显示全部楼层
强制退出的话,可以用endThread.同是这个函数要在线程中使用.不过不提倡用这种方法.
一般来说还是用TerminateThread();
给两个函数你参考一下:
void MyThread::WaitForThreadToTerminate( HANDLE hThread ) //等待线程终止
{
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;
希望对你有用.
|
|