Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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;
        }