1)我新建了一个线程类,不知道什么时候线程才调用InitInstance方法。
原以为是创建该线程对象时就调用,可是debug调式时没看它进去啊。
2)InitInstance方法中调用了WaitForSingleObject,那么CEvent.SetEvent()是该什么时候调用才好啊?
原以为是创建该线程对象时就调用,可是debug调式时没看它进去啊。
2)InitInstance方法中调用了WaitForSingleObject,那么CEvent.SetEvent()是该什么时候调用才好啊?
InitInstance返回真之后才进入Run函数之中,可以在InitInstance函数内调用WaitForSingleObject。
2.既然你使用了WaitForSingleObject函数等待一个事件,那么事件激活必须在其他线程中了,也就是说CEvent.SetEvent()要在其他线程中调用。不能在你创建的线程中调用
关于您的第二个回答我不太理解,就是CEvent.SetEvent()起的作用是什么?
难道是让WaitForSingleObject线程启动吗?
CEvent::SetEvent
BOOL SetEvent( );Return ValueNonzero if the function was successful, otherwise 0.ResSets the state of the event to signaled, releasing any waiting threads. If the event is manual, the event will remain signaled until ResetEvent is called. More than one thread can be released in this case. If the event is automatic, the event will remain signaled until a single thread is released. The system will then set the state of the event to nonsignaled. If no threads are waiting, the state remains signaled until one thread is released.是说SetEvent使CEvent处于一个有信号的状态