WaitForMultipleObjects(bWaitAll=true)双事件触发时返回值咨询
WaitForMultipleObjects Return Value for "Wait All" Scenario
Hey there! Let's break this down in simple terms since you're new to WinAPI and MSDN can feel overwhelming at first.
First, let's recap your code's intent: you're using WaitForMultipleObjects with the third parameter set to TRUE, which tells the function to only return when both of your 2 event handles are in a signaled state (since you set the timeout to 0, it's a quick check instead of blocking).
The Correct Return Value to Check
When bWaitAll = TRUE (the third argument), the function returns WAIT_OBJECT_0 if all objects in the handle array are signaled. That's the value you need to fill in the blank.
So your updated code will look like this:
if (WaitForMultipleObjects(2, lpHandles, TRUE, 0) == WAIT_OBJECT_0) { // Execute your desired action when both events are triggered } else { continue; }
Quick Clarifications to Avoid Confusion
- If not all objects are signaled (and your timeout is
0), the function will returnWAIT_TIMEOUTimmediately, so yourelseblock will run. - If something goes wrong (like invalid handles), the function returns
WAIT_FAILED—you can callGetLastError()to debug the issue if needed, but that's optional for your current flow. - Note that when
bWaitAll = FALSE(waiting for any single event), the return value would beWAIT_OBJECT_0orWAIT_OBJECT_0 + 1(indicating which specific event triggered). But since you're waiting for both,WAIT_OBJECT_0is the right check here.
内容的提问来源于stack exchange,提问作者Karim Zaher
相关产品推荐
相关产品推荐

