为什么我两次调用这个模块就会导致 程序死掉,无任何反应,
而且如果正常的话OUTPUT会输出
a CWinThread object at $01176A10, 64 bytes long
thrdcore.cpp(311) : {88} client block at 0x01176B80, subtype c0, 64 bytes long.
请各位执教,谢谢//程序代码
if( m_thread!=NULL)
{
DWORD ExitCode;
::GetExitCodeThread(m_thread->m_hThread,&ExitCode);
if(ExitCode == STILL_ACTIVE)
{
b_Draw=false; //快速退出执行模块
::WaitForSingleObject(m_thread->m_hThread,INFINITE);
delete m_thread;
m_thread=NULL;
}
}
b_Draw=true;
m_thread = AfxBeginThread(onthread,this);
m_thread->m_bAutoDelete = FALSE;
m_thread->ResumeThread();
而且如果正常的话OUTPUT会输出
a CWinThread object at $01176A10, 64 bytes long
thrdcore.cpp(311) : {88} client block at 0x01176B80, subtype c0, 64 bytes long.
请各位执教,谢谢//程序代码
if( m_thread!=NULL)
{
DWORD ExitCode;
::GetExitCodeThread(m_thread->m_hThread,&ExitCode);
if(ExitCode == STILL_ACTIVE)
{
b_Draw=false; //快速退出执行模块
::WaitForSingleObject(m_thread->m_hThread,INFINITE);
delete m_thread;
m_thread=NULL;
}
}
b_Draw=true;
m_thread = AfxBeginThread(onthread,this);
m_thread->m_bAutoDelete = FALSE;
m_thread->ResumeThread();
::ResetEvent(m_hEvent);线程函数里:for (;;)
{ if (WAIT_OBJECT_0 == ::WaitForSingleObject(m_hEvent,10000))
{
::CloseHandle(m_hEvent);
return 1;
}
}这样一来,能保证线程函数正常退出.
m_thread->m_bAutoDelete = FALSE; //要不可能
m_thread->ResumeThread();试试
m_thread->m_bAutoDelete = FALSE;
m_thread->ResumeThread(); //要不然到这里的时候可能线程已经退出把自己delete了..试试
GetExitCodeThread(pCCommThread->m_hThread, &ExitCode);
if (ExitCode == STILL_ACTIVE)
{
::WaitForSingleObject(pCCommThread->CommOpenSemaphore(), 10000);
delete pCCommThread;
pCCommThread = NULL;
}
在线程函数结束处释放信号量 if (m_hOpenSemaphore)
{
::ReleaseSemaphore(m_hOpenSemaphore, 1, NULL);
}
//创建线程
b_Draw=true;
m_thread = AfxBeginThread(onthread,this,CREATE_SUSPENT);
m_thread->m_bAutoDelete = FALSE;
m_thread->ResumeThread();if( m_thread!=NULL)
{
DWORD ExitCode;
::GetExitCodeThread(m_thread->m_hThread,&ExitCode);
if(ExitCode == STILL_ACTIVE)
{
b_Draw=false; //快速退出执行模块
::WaitForSingleObject(m_thread->m_hThread,INFINITE);
delete m_thread;
m_thread=NULL;
}
}还不行的话,建议用断点调试一下,看具体死在哪里