#include <afxwin.h>
#include <iostream>
using namespace std;
UINT ThreadProc(LPVOID)
{
for(int i=0;i<100;i++)
cout<<i<<endl;
return 0;
}
void main(int argc,TCHAR*argv[])
{
//Step 1 创建线程、“挂起”线程
CWinThread *pThread = AfxBeginThread(ThreadProc,NULL,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);
//Step 2 设为“非自动删除”、恢复线程
pThread->m_bAutoDelete = FALSE;
ResumeThread(pThread->m_hThread);
//Step 3 线程结束、“手动删除”pThread
if(WAIT_OBJECT_0 == WaitForSingleObject(pThread->m_hThread,INFINITE))
{
delete pThread;
pThread = NULL;
}
//Sleep(1000);
}
MFC创建线程02 AfxBeginThread .
最新推荐文章于 2020-08-20 14:44:57 发布