Premature Thread Termination
Terminating a thread prematurely is almost as simple: CallAfxEndThread from within the thread. Pass the desired exit code as the only parameter. This stops execution of the thread, deallocates the thread’s stack, detaches all DLLs attached to the thread, and deletes the thread object from memory.AfxEndThread must be called from within the thread to be terminated. If you want to terminate a thread from another thread, you must set up a communication method between the two threads.

解决方案 »

  1.   

    用PostThreadMessage,以前我提过一个相关的问题:
    http://www.csdn.net/expert/topic/94/94933.shtm
    _______________________________________________________________________________
    程序员论坛白庄http://www.baizhuang.net欢迎你的加盟!!
      

  2.   

    TerminateThread(HANDLE hThread,WORD dwExitCode)//CWinThread中有线程句柄,不建议使用。
    如果CWinThread可以接受WM_CLOSE等退出消息可以用PostMessage()发送退出消息。至于响应哪个消息,你查查吧!//推荐
      

  3.   

    为什么不自己继承一个CWinThread 类呢?又方便又安全:)
      

  4.   

    你从线程外面发一个消息,PostMessage();线程对这个消息做出反应,在执行函数体中PostQuitMessage();
      

  5.   

    不好意思,上面的PostMessage()应该改为PostThreadMessage()
      

  6.   

    我使用了TerminateThread(),效果很好,
    我给大家分了。