你不能使用AfxBeginThread(),需要改用CreateThread()。
HANDLE m_hYourThread; // 线程句柄,声明成一个成员变量
HANDLE m_hYourEvent; // 事件句柄,用来通知线程结束
// 初始化的时候增加这两句
m_hYourThread = NULL;
m_hYOurEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
// 创建的时候
DWORD dwThreadId;
m_hYourThread = CreateThread(NULL,0,YourThread,this,0,&dwThreadId);
// 线程内部
while (1) 改成: while (WAIT_TIMEOUT == WaitForSingleObject(m_hYourThred, 10000)) {
}
return 0;
// 退出的时候
SetEvent(m_hYourEvent);
if (WAIT_TIMEOUT == WaitForSingleObject(m_hYourThread,1000)
TerminateThread(m_hYourThread);
CloseHandle(m_hYourThread);
CloseHandle(m_hYourEvent);
HANDLE m_hYourThread; // 线程句柄,声明成一个成员变量
HANDLE m_hYourEvent; // 事件句柄,用来通知线程结束
// 初始化的时候增加这两句
m_hYourThread = NULL;
m_hYOurEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
// 创建的时候
DWORD dwThreadId;
m_hYourThread = CreateThread(NULL,0,YourThread,this,0,&dwThreadId);
// 线程内部
while (1) 改成: while (WAIT_TIMEOUT == WaitForSingleObject(m_hYourThred, 10000)) {
}
return 0;
// 退出的时候
SetEvent(m_hYourEvent);
if (WAIT_TIMEOUT == WaitForSingleObject(m_hYourThread,1000)
TerminateThread(m_hYourThread);
CloseHandle(m_hYourThread);
CloseHandle(m_hYourEvent);