コード例 #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);
        }
コード例 #2
0
ファイル: Scheduler.cs プロジェクト: sandboxorg/scheduler
        /// <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);
            }
        }
コード例 #3
0
ファイル: Scheduler.cs プロジェクト: sandboxorg/scheduler
        /// <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);
        }