MsgWaitForMultipleObjects函数未进入WAIT_TIMEOUT情况。 [英] MsgWaitForMultipleObjects function not entering WAIT_TIMEOUT case.
问题描述
我们正在使用visual c ++ 编写一个使用comm端口与设备通信的应用程序,并从中获取响应。
我们正在使用函数MsgWaitForMultipleObjects来等待。该函数如下所示。
unsigned long dwRes;
while(true)
{
dwRes = MsgWaitForMultipleObjects(1,& m_hPPMsgResponseReceived,false,80,QS_ALLINPUT);
switch(dwRes)
{
case WAIT_OBJECT_0:
//让我们返回
LogError(" WaitOnResponseEvent",EVENT_TYPE_ERROR,2 ,"%s","event。";;
ResetEvent(m_hPPMsgResponseReceived);
返回;
case WAIT_OBJECT_0 + 1:
//处理消息
MSG msg;
//查看是否有任何消息要处理
while(PeekMessage(& msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(& msg) ;
DispatchMessage(& msg);
}
休息;
case WAIT_TIMEOUT:
LogError(" WaitOnResponseEvent",EVENT_TYPE_ERROR,2,"%s","等待超时。");
ResetEvent(m_hPPMsgResponseReceived);
返回;
默认值:
LogError(" WaitOnResponseEvent",EVENT_TYPE_ERROR,2,"%s"," default case reach");
返回;
}
}
在这种情况下,超时值为80毫秒,因为它可以在函数中看到。
问题在于,在某些系统中,有时(并非总是),即使时间超过80毫秒,该功能也不会进入WAIT_TIMEOUT情况。由于这个原因,MsgWaitForMultipleObjects没有返回。
有人能告诉我们可能导致这种情况的原因吗?请告诉我们在代码中需要调整的任何内容。或者内部的窗口发生了什么?
请告诉我们,以便我们能够阻止这种情况发生。
提前致谢。
Satyanvesh D
查看此文章:
- < a href ="http://blogs.msdn.com/b/oldnewthing/archive/2005/02/17/375307.aspx"> http://blogs.msdn.com/b/oldnewthing/archive/2005/02 /17/375307.aspx 跨度>
We are using visual c++ to write an application which uses comm port to communicate to a device and also get a response back from it.
We are using a function MsgWaitForMultipleObjects to wait. The function looks like the following.
unsigned long dwRes;
while( true ) { dwRes=MsgWaitForMultipleObjects(1, &m_hPPMsgResponseReceived, false, 80, QS_ALLINPUT); switch(dwRes) { case WAIT_OBJECT_0: // let's return LogError("WaitOnResponseEvent", EVENT_TYPE_ERROR, 2, "%s","event."); ResetEvent(m_hPPMsgResponseReceived); return; case WAIT_OBJECT_0 + 1: // process the messages MSG msg; // see if there are any messages to process while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { TranslateMessage(&msg); DispatchMessage(&msg); } break; case WAIT_TIMEOUT: LogError("WaitOnResponseEvent", EVENT_TYPE_ERROR, 2, "%s", "after wait for timeout."); ResetEvent(m_hPPMsgResponseReceived); return; default: LogError("WaitOnResponseEvent", EVENT_TYPE_ERROR, 2, "%s", "default case reached"); return; } }
The timeout value is 80 milliseconds in this case as it can be seen in the function.
The problem is that, in some systems and sometimes (not always) the function is not entering into the WAIT_TIMEOUT case even when the time exceeds 80 milliseconds. Due to this the MsgWaitForMultipleObjects is not returning.
Can somebody let us know what might be causing this? please let us know anything that needs to be adjusted in our code. Or something is happening in the windows internally?
Please let us know so that we can stop this happening.
Thanks in advance.
Satyanvesh D
Check this article:
这篇关于MsgWaitForMultipleObjects函数未进入WAIT_TIMEOUT情况。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!