另一个贴:
http://community.csdn.net/Expert/topic/3757/3757242.xml?temp=.0368616
谁有例子啊?UINT MyThread( LPVOID lParam )
{
while(true);
return 0;
}void MyDeal(void* vParam)
{
HANDLE hThread;
hThread=AfxBeginThread((AFX_THREADPROC)MyThread, (LPVOID)vParam);
if(hThread==NULL)
AfxMessageBox("Error!");

return;
}
void CTestView::OnButton1() 
{
//开始 char *str1 = new char[10];
_beginthread(MyDeal, 0, (void*)(str1) );
}void CTestView::OnButton2() 
{
//结束
}

解决方案 »

  1.   

    子线程的while里面放检查消息的非堵塞代码,如果收到某特定消息就退出while。 通知线程可以postthreadmessage该特定消息给子线程。子线程id可以用全局变量保存。
      

  2.   

    while(true)--->
    HANDLE m_hEventKill;
    m_hEventKill = CreateEvent(NULL, TRUE, FALSE, NULL);while(WaitForSingleObject(m_hEventKill,50)==WAIT_TIMEOUT)
    {
    }关闭时:
    SetEvent(m_hEventKill);
      

  3.   

    我可能需要强制关闭线程,因为用了ReadDirectoryChangesW
    bMon为全局变量,
    我在OnButton1() 里将其置为true然后启动线程,在OnButton2() 里将其置为false,让线程自己退出,但不成功,因为"暂停"在ReadDirectoryChangesW上了.while(bMon)
    {
    //ReadDirectoryChangesW)
    //此处可能会等待很久,所以要强制关闭线程
    }