コード例 #1
0
ファイル: WaitableCounter.cs プロジェクト: herbqiao/paint.net
        public WaitableCounter(int maxCount)
        {
            if (maxCount < 1 || maxCount > 64)
            {
                throw new ArgumentOutOfRangeException("maxCount", "must be between 1 and 64, inclusive");
            }

            this.freeEvents = new WaitHandleArray(maxCount);
            this.inUseEvents = new WaitHandleArray(maxCount);

            for (int i = 0; i < maxCount; ++i)
            {
                this.freeEvents[i] = new ManualResetEvent(true);
                this.inUseEvents[i] = new ManualResetEvent(false);
            }

            this.theLock = new object();
        }
コード例 #2
0
        public override void OnEnteredState()
        {
            this.checkingEvent.Reset();
            this.abortEvent.Reset();

            ThreadPool.QueueUserWorkItem(new WaitCallback(DoCheckThreadProc));

            WaitHandleArray events = new WaitHandleArray(2);
            events[0] = this.checkingEvent;
            events[1] = this.abortEvent;
            int waitResult = events.WaitAny();

            if (waitResult == 0 && manifest != null && latestVersionIndex != -1)
            {
                StateMachine.QueueInput(PrivateInput.GoToUpdateAvailable);
            }
            else if (waitResult == 1)
            {
                StateMachine.QueueInput(PrivateInput.GoToAborted);
            }
            else if (this.exception != null)
            {
                StateMachine.QueueInput(PrivateInput.GoToError);
            }
            else
            {
                StateMachine.QueueInput(PrivateInput.GoToDone);
            }
        }