1、class myClass
{
public:
HANDLE m_exitThreadEvent;
......
}
2、m_exitThreadEvent = CreateEvent(NULL,FALSE,FALSE,NULL); //创建通讯线程退出事件句柄,第三个参数为FALSE表示初始时无信号
3、ResetEvent(m_exitThreadEvent ); //重置事件为无信号
4、SetEvent(m_exitThreadEvent ); //设置退出事件为有信号
5、以接收到此信号作为通讯线程的退出条件:
myClass *pMyClass;
while(1)
{
if(WaitForSingleObject(pMyClass->m_exitThreadEvent ,0) == WAIT_OBJECT_0)
{
break:
}
......
return 1;
}
5、关闭退出线程事件句柄:
CloseHandle(m_exitThreadEvent );