Esempio n. 1
0
        internal IAsyncResult BeginWait(int millis, AsyncCallback callback, object state)
        {
            VerifyTaskManager();

            lock (_waiters)
            {
                _waiters.Add(callback);
            }

            if (millis == Timeout.Infinite) // task will wait forever till pulsed
                return null;

            if (millis <= 0)
                throw new ArgumentException("Argument must be greater than zero");

            AsyncTimer timer = new AsyncTimer();

            timer.Start(millis, delegate(IAsyncResult ar) {
                ((IDisposable)timer).Dispose();

                bool timedOut = false;
                lock(_waiters) {
                    if (_waiters.Contains(callback)) // timed out
                    {
                        timedOut = true;
                        _waiters.Remove(callback);
                    }
                }
                if (timedOut)
                    callback(BoolResult.FalseValue);
            }, null);

            return null;
        }
Esempio n. 2
0
        private IAsyncCall GotoSleep(int millis)
        {
            if (millis <= 0)
            {
                throw new ArgumentException("Argument must be greater than zero");
            }

            if (_timer == null)
            {
                _timer = new AsyncTimer();
            }

            return(_waitCall
                   .WaitOn(cb => _timer.Start(millis, cb, null)) & _timer.End);
        }
Esempio n. 3
0
        protected virtual void Dispose(bool disposing)
        {
            TaskState = TaskState.Terminated;

            if (_asyncCallIterator != null)
            {
                _asyncCallIterator.Dispose();
                _asyncCallIterator = null;
            }

            if (_timer != null)
            {
                ((IDisposable)_timer).Dispose();
                _timer = null;
            }
        }
Esempio n. 4
0
        internal IAsyncResult BeginWait(int millis, AsyncCallback callback, object state)
        {
            VerifyTaskManager();

            lock (_waiters)
            {
                _waiters.Add(callback);
            }

            if (millis == Timeout.Infinite) // task will wait forever till pulsed
            {
                return(null);
            }

            if (millis <= 0)
            {
                throw new ArgumentException("Argument must be greater than zero");
            }

            AsyncTimer timer = new AsyncTimer();

            timer.Start(millis, delegate(IAsyncResult ar) {
                ((IDisposable)timer).Dispose();

                bool timedOut = false;
                lock (_waiters) {
                    if (_waiters.Contains(callback)) // timed out
                    {
                        timedOut = true;
                        _waiters.Remove(callback);
                    }
                }
                if (timedOut)
                {
                    callback(BoolResult.FalseValue);
                }
            }, null);

            return(null);
        }
Esempio n. 5
0
        private IAsyncCall GotoSleep(int millis)
        {
            if (millis <= 0)
                throw new ArgumentException("Argument must be greater than zero");

            if (_timer == null)
                _timer = new AsyncTimer();

            return _waitCall
                .WaitOn(cb => _timer.Start(millis, cb, null)) & _timer.End;
        }
Esempio n. 6
0
        protected virtual void Dispose(bool disposing)
        {
            TaskState = TaskState.Terminated;

            if (_asyncCallIterator != null)
            {
                _asyncCallIterator.Dispose();
                _asyncCallIterator = null;
            }

            if (_timer != null)
            {
                ((IDisposable)_timer).Dispose();
                _timer = null;
            }
        }