Exemplo n.º 1
0
        public IDisposable Schedule(TimeSpan delay, Action <IScheduler> action)
        {
            var timeoutObj = new TimeoutObject(action, this.Now.Add(delay));

            this._timeoutObjects.Add(timeoutObj);

            return(timeoutObj);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes the action and stops the thread if necessary.
        /// </summary>
        /// <param name="timeoutObj">The timeout obj.</param>
        private void RemoveInternal(TimeoutObject timeoutObj)
        {
            lock (this._timeoutObjects)
            {
                this._timeoutObjects.Remove(timeoutObj);
                if (this._timeoutObjects.Count == 0)
                {
                    this.StopTimerThread();
                }

                Monitor.PulseAll(this._timeoutObjects);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the action and starts the thread if necessary.
        /// </summary>
        /// <param name="timeoutObj">The timeout obj.</param>
        private IDisposable AddInternal(TimeoutObject timeoutObj)
        {
            lock (this._timeoutObjects)
            {
                this._timeoutObjects.Add(timeoutObj);
                if (this._timeoutObjects.Count == 1)
                {
                    this.StartTimerThread();
                }

                Monitor.PulseAll(this._timeoutObjects);
            }

            return(timeoutObj);
        }