Is it a valid way to put 2 WaitForSingleObject in a 'if' condtion. and I know it can be re-written using WaitForMuiltipleObject. But I wanted to know if I use below code would lead to any problems..?
CHandle m_hEventUDP;
CHandle m_hEventTCP;
if (WaitForSingleObject(m_hEventUDP, 1500) == WAIT_OBJECT_0 || WaitForSingleObject(m_hEventTCP, 1500) == WAIT_OBJECT_0)
{
//An event is triggered(among 2)
//I don't care which event is triggered among 2, either of one is Okay for me
}
else
{
//No event is triggered
}
That will wait for the first one, and if that doesn't happen (and times out) only then will it wait for the second one. You can have one of three situations:
With WaitForMultipleObjects you will get this behaviour:
So in your current code you will have a 1.5 second latency added on in common cases, which the multiple objects wait avoids.