另一个贴:
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()
{
//结束
}
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()
{
//结束
}
HANDLE m_hEventKill;
m_hEventKill = CreateEvent(NULL, TRUE, FALSE, NULL);while(WaitForSingleObject(m_hEventKill,50)==WAIT_TIMEOUT)
{
}关闭时:
SetEvent(m_hEventKill);
bMon为全局变量,
我在OnButton1() 里将其置为true然后启动线程,在OnButton2() 里将其置为false,让线程自己退出,但不成功,因为"暂停"在ReadDirectoryChangesW上了.while(bMon)
{
//ReadDirectoryChangesW)
//此处可能会等待很久,所以要强制关闭线程
}