我在一个子线程里面的自定义消息响应函数里
有如下语句
CEvent event_CloseServer;
event_CloseServer.Lock(); 
当执行到event_CloseServer.Lock();时发生异常

解决方案 »

  1.   

    用SetEvent()和ResetEvent(   );   
      再加上   
      DWORD   WaitForSingleObject(   
          HANDLE   hHandle,                   
          DWORD   dwMilliseconds         
      );   
      用他们去同步线程
      

  2.   

    那这个CEvent对象不能在这里构造。
      

  3.   

    同步线程不能用Cevent的lock。这是MSDN上的解释
    To access or release a CEvent object, create a CMultiLock or CSingleLock object and call its Lock and Unlock member functions. To change the state of a CEvent object to signaled (threads do not have to wait), call SetEvent or PulseEvent. To set the state of a CEvent object to nonsignaled (threads must wait), call ResetEvent.
    lock是访问那个Event对象的
      

  4.   

    要等待,就这个线程用  DWORD  WaitForSingleObject(  
          HANDLE  hHandle,                  
          DWORD  dwMilliseconds        
      );  其他线程工作完成了就  用SetEvent()
      

  5.   

    我这样用
    CEvent event_CloseServer;定义成全局的; WaitForSingleObject(event_CloseServer.m_hObject,,INFINITE);
    然后在waitfor处异常了
      

  6.   

    查一下event_CloseServer中的数据是否被修改过。