/// <summary> /// Waits for all references to be released while disallowing /// attempts to acquire rundown protection. /// </summary> /// <param name="millisecondsTimeout">The timeout, in milliseconds.</param> /// <returns>Whether all references were released.</returns> public bool Wait(int millisecondsTimeout) { // Fast path. Just in case there are no users, we can go ahead // and set the active flag and exit. Or if someone has already // initiated the rundown, exit as well. int value = Interlocked.CompareExchange(ref this._value, RundownActive, 0); if (value == 0 || value == RundownActive) { return(true); } // Set the rundown active flag. do { value = _value; } while (Interlocked.CompareExchange( ref _value, value | RundownActive, value ) != value); // Wait for the event, but only if we had users. if ((value & ~RundownActive) != 0) { return(_wakeEvent.Wait(millisecondsTimeout)); } return(true); }
protected override bool WaitOneInternal(int timeout) { return(fe.Wait(timeout)); }