为什么我两次调用这个模块就会导致 程序死掉,无任何反应,
而且如果正常的话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();

解决方案 »

  1.   

    请你看看这里,一般的线程要这样写:HANDLE m_hEvent = ::CreateEvent(NULL,TRUE,FALSE,"");
    ::ResetEvent(m_hEvent);线程函数里:for (;;)
    {      if (WAIT_OBJECT_0 == ::WaitForSingleObject(m_hEvent,10000))
          {
              ::CloseHandle(m_hEvent);
              return 1;
          }
    }这样一来,能保证线程函数正常退出.
      

  2.   

    m_thread = AfxBeginThread(onthread,this); //这里指定CREATE_SUSPENDED
        m_thread->m_bAutoDelete = FALSE; //要不可能
        m_thread->ResumeThread();试试
      

  3.   

    m_thread = AfxBeginThread(onthread,this); //这里指定CREATE_SUSPENDED
        m_thread->m_bAutoDelete = FALSE; 
        m_thread->ResumeThread();  //要不然到这里的时候可能线程已经退出把自己delete了..试试
      

  4.   

    因为你把m_bAutoDelete设置为FALSE了,所以m_thread这个指针直向的对象,需要你手动释放掉。不释放会出现问题。
      

  5.   

    在线程退出时候设置一个信号量
    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);
    }
      

  6.   

    修改一下:
    //创建线程
    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;
            }
        }还不行的话,建议用断点调试一下,看具体死在哪里