线程的创建:
HANDLE hThreadExit = CreateEvent(NULL, TRUE, FALSE, NULL);
CWinThread* pThread = AfxBeginThread(Thread, threadparamter, 0, 0, CREATE_SUSPENDED);
pThread ->m_bAutoDelete = FALSE;
pThread ->ResumeThread();
线程:
UINT Thread(LPVOID lParam)
{
while(WaitForSingleObject(hThreadExit, 1000) == WAIT_TIMEOUT)
{
Sleep(1);
}
return 0;
}
线程的结束:
SetEvent(hThreadExit );
if(pThread != NULL)
{
WaitForSingleObject(pThread ->m_hThread, INFINITE);
delete pThread ;
pThread = NULL;
}
CloseHandle(hThreadExit );