Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semaphore timeout mechanism in C#

Does anyone know how .NET handles a timeout on a call to Semaphore.WaitOne(timeout)?

I'd expect a TimeoutException, but the MSDN documentation doesn't list this in the list of expected exceptions, and I can't seem to find it documented anywhere.

like image 640
James King Avatar asked Sep 16 '09 06:09

James King


1 Answers

The method will return false if it times out, and true if it returns a signal:

if (mySemaphore.WaitOne(1000))
{
    // signal received
}
else
{
    // wait timed out
}
like image 141
Fredrik Mörk Avatar answered Oct 08 '22 21:10

Fredrik Mörk