示例#1
0
        public void Set()
        {
            List <AsyncWaitHandle.AsyncWaiter> asyncWaiters = null;

            AsyncWaitHandle.AsyncWaiter item = null;
            if (!this.isSignaled)
            {
                lock (this.syncObject)
                {
                    if (!this.isSignaled)
                    {
                        if (this.resetMode == EventResetMode.ManualReset)
                        {
                            this.isSignaled = true;
                            Monitor.PulseAll(this.syncObject);
                            asyncWaiters      = this.asyncWaiters;
                            this.asyncWaiters = null;
                        }
                        else if (this.asyncWaiters == null || this.asyncWaiters.Count <= 0)
                        {
                            this.isSignaled = true;
                        }
                        else
                        {
                            item = this.asyncWaiters[0];
                            this.asyncWaiters.RemoveAt(0);
                        }
                    }
                }
            }
            if (asyncWaiters != null)
            {
                foreach (AsyncWaitHandle.AsyncWaiter asyncWaiter in asyncWaiters)
                {
                    asyncWaiter.CancelTimer();
                    asyncWaiter.Call();
                }
            }
            if (item != null)
            {
                item.CancelTimer();
                item.Call();
            }
        }
示例#2
0
        private static void OnTimerComplete(object state)
        {
            AsyncWaitHandle.AsyncWaiter asyncWaiter = (AsyncWaitHandle.AsyncWaiter)state;
            AsyncWaitHandle             parent      = asyncWaiter.Parent;
            bool flag = false;

            lock (parent.syncObject)
            {
                if (parent.asyncWaiters != null && parent.asyncWaiters.Remove(asyncWaiter))
                {
                    asyncWaiter.TimedOut = true;
                    flag = true;
                }
            }
            asyncWaiter.CancelTimer();
            if (flag)
            {
                asyncWaiter.Call();
            }
        }
示例#3
0
        public bool WaitAsync(Action <object, TimeoutException> callback, object state, TimeSpan timeout)
        {
            bool flag;

            if (!this.isSignaled || this.isSignaled && this.resetMode == EventResetMode.AutoReset)
            {
                lock (this.syncObject)
                {
                    if (this.isSignaled && this.resetMode == EventResetMode.AutoReset)
                    {
                        this.isSignaled = false;
                    }
                    else if (!this.isSignaled)
                    {
                        AsyncWaitHandle.AsyncWaiter asyncWaiter = new AsyncWaitHandle.AsyncWaiter(this, callback, state);
                        if (this.asyncWaiters == null)
                        {
                            this.asyncWaiters = new List <AsyncWaitHandle.AsyncWaiter>();
                        }
                        this.asyncWaiters.Add(asyncWaiter);
                        if (timeout != TimeSpan.MaxValue)
                        {
                            if (AsyncWaitHandle.timerCompleteCallback == null)
                            {
                                AsyncWaitHandle.timerCompleteCallback = new Action <object>(AsyncWaitHandle.OnTimerComplete);
                            }
                            asyncWaiter.SetTimer(AsyncWaitHandle.timerCompleteCallback, asyncWaiter, timeout);
                        }
                        flag = false;
                        return(flag);
                    }
                    return(true);
                }
                return(flag);
            }
            return(true);
        }