Jim Fell
Jim Fell

Reputation: 14264

WaitForSingleObject Does Not Time Out - C++

My console application calls WaitForSingleObject in the parent thread with a timeout value of 5 seconds.

dwObjectWaitState = ::WaitForSingleObject( s_hRxDataEvent, 50000L );

After configuring the physical environment (i.e. no code changes), so that the event will never get signaled, I set a breakpoint at the following line, and run the application. The PC never gets to the breakpoint. s_hRxDataEvent is a valid event handle that is normally set in a child thread. The application works great when the physical environment is configured as expected. Why doesn't the function time out? Thanks.

Upvotes: 0

Views: 788

Answers (4)

Praetorian
Praetorian

Reputation: 109279

The timeout value for WaitForSingleObject is specified in milliseconds, so 50000L means 50 seconds, not 5 seconds.

Upvotes: 1

Sonny Saluja
Sonny Saluja

Reputation: 7287

50000L milliseconds = 50 seconds.

Upvotes: 1

Note that you have an extra zero there.

Upvotes: 1

casablanca
casablanca

Reputation: 70731

The timeout is in milliseconds. 50000 is 50 seconds, not 5 seconds.

Upvotes: 2

Related Questions