WaitForSingleObject的用法

一般用来线程(或者类似线程机制)的同步

 

 // TODO: Add your control notification handler code here
 CEvent obj;
 obj.SetEvent();
 DWORD a = WaitForSingleObject(obj.m_hObject,100);
 
 CString str;
 str.Format(L"%x",a); ///0表示等到了,成功

 this->MessageBox(str);

 

 

 

 // TODO: Add your control notification handler code here
 CEvent obj;

obj.ResetEvent();//这句话可加,可不加

 DWORD a = WaitForSingleObject(obj.m_hObject,100);
 
 CString str;
 str.Format(L"%x",a); /// 102表示Timeout,失败

 this->MessageBox(str);

 

你可能感兴趣的:(WaitForSingleObject的用法)