Esempio n. 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)
                        {
                            if (this.syncWaiterCount <= 0)
                            {
                                if (this.asyncWaiters == null || this.asyncWaiters.Count <= 0)
                                {
                                    this.isSignaled = true;
                                }
                                else
                                {
                                    item = this.asyncWaiters[0];
                                    this.asyncWaiters.RemoveAt(0);
                                }
                            }
                            else
                            {
                                Monitor.Pulse(this.syncObject);
                            }
                        }
                        else
                        {
                            this.isSignaled = true;
                            Monitor.PulseAll(this.syncObject);
                            asyncWaiters      = this.asyncWaiters;
                            this.asyncWaiters = null;
                        }
                    }
                }
            }
            if (asyncWaiters != null)
            {
                foreach (AsyncWaitHandle.AsyncWaiter asyncWaiter in asyncWaiters)
                {
                    asyncWaiter.CancelTimer();
                    asyncWaiter.Call();
                }
            }
            if (item != null)
            {
                item.CancelTimer();
                item.Call();
            }
        }
Esempio n. 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;
                }
            }
            asyncWaiter.CancelTimer();
            if (flag)
            {
                asyncWaiter.Call();
            }
        }
Esempio n. 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)
                    {
                        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);
                        }
                    }
                    else
                    {
                        this.isSignaled = false;
                    }
                    return(true);
                }
                return(flag);
            }
            return(true);
        }
Esempio n. 4
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)
					{
						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;
						}
					}
					else
					{
						this.isSignaled = false;
					}
					return true;
				}
				return flag;
			}
			return true;
		}