private void SetTimer(uint actualDuration) { // This function is called with the TimerQueue lock acquired Debug.Assert(Lock.IsAcquired); // Note: AutoResetEvent.WaitOne takes an Int32 value as a timeout. // The TimerQueue code ensures that timer duration is not greater than max Int32 value Debug.Assert(actualDuration <= (uint)Int32.MaxValue); s_nextTimerDuration = (int)actualDuration; // If this is the first time the timer is set then we need to create a thread that // will manage and respond to timer requests. Otherwise, simply signal the timer thread // to notify it that the timer duration has changed. if (s_timerEvent == null) { s_timerEvent = new AutoResetEvent(false); ThreadPool.QueueLongRunningWork(TimerThread); } else { s_timerEvent.Set(); } }