private void DelayThreadPool() { if (DelayEvent == null) { DelayEvent = WaitEventFactory.Create(isCompleted: true, useSlim: true); } DelayEvent.Begin(); ThreadPool.QueueUserWorkItem((s) => { DelaySleep(); DelayEvent.Complete(); }); DelayEvent.Wait(); }
/// <summary> /// Implementation using a Timer with a wait event. /// </summary> private void DelayTimerEvent() { const int timeoutMilliseconds = 15; lock (SyncRoot) { if (DelayEvent == null) { DelayEvent = WaitEventFactory.Create(isCompleted: false, useSlim: false); } if (DelayTimer == null) { DelayTimer = new Timer((s) => DelayEvent.Complete(), DelayEvent, timeoutMilliseconds, timeoutMilliseconds); } DelayEvent.Wait(TimeSpan.FromMilliseconds(timeoutMilliseconds)); DelayEvent.Begin(); } }