mfc強行關閉線程

BOOL CCloudForensicsBaiduNetDiskDlg::EndThread()
{
	if(!m_pThread)
		return FALSE;
	DWORD uExitCode;
	GetExitCodeThread(m_pThread->m_hThread,&uExitCode);
	if(uExitCode == STILL_ACTIVE)
	{

		if(GetSafeHwnd())
		{
			SetTimer(123,1000,NULL);
		}
		else
		{
			DWORD dwWaitResult =  WaitForSingleObject(m_pThread->m_hThread, 10000);
			ASSERT(WAIT_FAILED != dwWaitResult ); 
			if(WAIT_TIMEOUT == dwWaitResult ) 
			{
				if(!ForceTerminate())
				{
					CDialogEx::OnCancel();
					return FALSE;
				}
				CDialogEx::OnCancel();
			}
		}
	}
	return TRUE;
}
BOOL CCloudForensicsBaiduNetDiskDlg::ForceTerminate()
{
	BOOL bRes = TRUE;
	if(m_pThread && m_pThread->m_hThread)
	{
		bRes = TerminateThread(m_pThread->m_hThread,0);
		SAFE_DELETE(m_pThread);
	}
	return bRes;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章