子线程的handle
在主线程里WaitForSingleObject(handle,INIFLE);

解决方案 »

  1.   

    WaitForSingleObjct
    把子线程的ID作为参数
    pos=m_ptrlstThreadScheduled.GetHeadPosition();
    while(pos){
    pMultiThread=m_ptrlstThreadScheduled.GetNext(pos);
    delete pMultiThread;
    }
    m_ptrlstThreadScheduled.RemoveAll();
    ////notify kill to running threads
    pos=m_ptrlstThreadRunning.GetHeadPosition();
    while(pos){
    pMultiThread=m_ptrlstThreadRunning.GetNext(pos);
    VERIFY(pMultiThread->m_eventKill.SetEvent());
    }
    //wait for running threads to finish
    for (int nThreadsLeft = m_ptrlstThreadRunning.GetCount(); nThreadsLeft != 0; ){
    WaitForSingleObject(CMultiThread::m_eventAnotherDead, INFINITE);
    Sleep(nThreadsLeft*2);// 200ms for every 100 threads
    nThreadsLeft = 0;
    pos=m_ptrlstThreadRunning.GetHeadPosition();
    while(pos){
    pMultiThread=m_ptrlstThreadRunning.GetNext(pos);
    if (!pMultiThread->IsDead())
    ++nThreadsLeft;
    }
    }
    // delete all running thread objects
    while (!m_ptrlstThreadRunning.IsEmpty())
    {
    pMultiThread= m_ptrlstThreadRunning.RemoveHead();
    VERIFY(WaitForSingleObject(pMultiThread->m_hThread, INFINITE) == WAIT_OBJECT_0);
    delete pMultiThread;
    }
      

  2.   

    回复(mfcsdk())
    你说的这种方式我试过,有时候四锁在WaitForSingleObject(handle,INIFLE); 函数!
      

  3.   

    1:用WAITFORSINGLEOBJECT等待线程对象。
    2:用GETEXITCODETHREAD来轮循线程退出CODE。