title: WaitOne() timeout parameter lost?
body: <p>why <code>System.Threading.WaitHandle.WaitOne()</code> hasn't overload for the timeout parameters as available in standard .NET implementation: <a href="http://msdn.microsoft.com/en-us/library/cc189907%28v=vs.110%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/cc189907(v=vs.110).aspx</a></p>
  
  <p>It's very useful in working threads when, during thread sleep, thread is requested to stop from Main UI thread.. Other ways to implement it?</p>
  
  <p>Example:</p>
  
  <pre><code>public void StartBatteryAnimation()
  { 
    whStopThread = new ManualResetEvent(false);
  
    batteryAnimationThread = new Thread(new ThreadStart(BatteryAnimation_Callback));
    batteryAnimationThread.Start();
  }
  
  public void StopBatteryAnimation()
  { 
    whStopThread.Set();      
  
    batteryAnimationThread.Join();
  
    batteryAnimationThread = null;
    whStopThread.Dispose();
    whStopThread = null;
  }
  
  public void BatteryAnimation_Callback()
  { 
      bool exitResult = false;
  
      while (true)
      {
        // Do some stuff
        exitResult = whStopThread.WaitOne(WAIT_INTERVALL);
        if (exitResult) break;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Thanks Frank for your (1000th!!) reply.</p>
  
  <p>So my custom implementation for <code>WaitHandle.WaitOne(int Timeout)</code> has been:</p>
  
  <pre><code>private Thread    batteryAnimationThread     = null;
  private Semaphore batteryAnimationSemaphore  = null;
  
  public void StartBatteryAnimation()
  { 
    batteryAnimationSemaphore = new Semaphore(1);
    batteryAnimationSemaphore.Acquire();
  
    batteryAnimationThread = new Thread(new ThreadStart(BatteryAnimation_Callback));
    batteryAnimationThread.Start();
  }
  
  public void StopBatteryAnimation()
  { 
    batteryAnimationSemaphore.Release();
  
    batteryAnimationThread.Join();
  
    batteryAnimationThread    = null;
    batteryAnimationSemaphore = null;
  }
  
  public void BatteryAnimation_Callback()
  { 
    bool stopThread = false;
  
    try
    {
      while (true)
      {
        // Do some stuff..
  
        stopThread = batteryAnimationSemaphore.TryAcquire(1, BATTERY_ANIMATION_INTERVALL, Java.Util.Concurrent.TimeUnit.MILLISECONDS);
  
        if (stopThread) break;
    }
    catch (Exception ex)
    { 
    }
  
    batteryAnimationSemaphore.Release();
  }
  </code></pre>
  
  <p>Is this the right way for?</p>
  
  <p>Thanks</p>