我的线程为什么中止不了呢?很急!!!!!!!!!
我线程的流程是:
UINT CMyClass::ThreadProc(LPVOID pParam)
{
CMyClass* myclass = (CMyClass*) pParam;
while( !(myclass->m_bStop)) //true)
{
........//My work
}
return 0;
}
void MyClass::StartThread()
{
CWinThread* pThread = AfxBeginThread(ThreadProc, this);
if (pThread!=NULL)
{
m_hThread = pThread->m_hThread;
m_bStop = false;
}
}
void MyClass::EndThread()
{
//终止线程
m_bStop = true;
WaitForSingleObject(m_hThread, INFINITE)
}
我在MyProjectAPP中调用EndThread(),我单步执行,程序一旦跳到这个函数中,好像整个程序都死了,线程卡在一个地方退不出来了,waitforsingleobject无限等待。为什么?哪会出问题呢?