コード例 #1
0
        private void DelayThreadPool()
        {
            if (DelayEvent == null)
            {
                DelayEvent = WaitEventFactory.Create(isCompleted: true, useSlim: true);
            }

            DelayEvent.Begin();
            ThreadPool.QueueUserWorkItem((s) =>
            {
                DelaySleep();
                DelayEvent.Complete();
            });

            DelayEvent.Wait();
        }
コード例 #2
0
        /// <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();
            }
        }