title: .NET 4.5 Semaphore WaitOne(0) doesn't block, but decrements semaphore count
body: <p>Up to the <a href="http://msdn.microsoft.com/en-us/library/cc189907%28v=vs.110%29.aspx" rel="nofollow">documentation</a> of .NET 4.5 if I use WaitOne(Int32) method on some object of Semaphore class (or - generally - WaitHandle class) with 0 (zero) as its argument, it doesn't block and may be used for testing semaphore's current state:</p>
  
  <p>"If millisecondsTimeout is zero, the method does not block. It tests the state of the wait handle and returns immediately."</p>
  
  <p>To me it's highly confusing (or even misleading), because it doesn't block, but it decrements semaphore count by one. So if I use it like this:</p>
  
  <pre><code>If (!mySemaphore.WaitOne(0)) DoSomething();
  </code></pre>
  
  <p>then it may decrement my semaphore (if true), causing other threads to be unable to run. So we cannot use it like this for only testing semaphore's state. The correct use should be</p>
  
  <pre><code>If (!mySemaphore.WaitOne(0)) DoSomething();
  Else mySemaphore.Release();
  </code></pre>
  
  <p>So it doesn't only test semaphore's state! Am I right?</p>