コード例 #1
0
 void Add(TestDelayedTask ttask)
 {
     lock (this)
     {
         queue.Add(ttask);
     }
 }
コード例 #2
0
 void Remove(TestDelayedTask ttask)
 {
     lock (this)
     {
         queue.Remove(ttask);
     }
 }
コード例 #3
0
        /// <summary>
        /// Schedule a task for non-delayed execution.
        /// </summary>
        /// <param name="task">The task to schedule.</param>
        /// <returns>The IDisposable that allows cancelling the execution of the task.</returns>
        public IDisposable Schedule(Action task)
        {
            TestDelayedTask tt = new TestDelayedTask(task, Now, NewId(), this, null);

            Add(tt);
            return(tt);
        }
コード例 #4
0
        /// <summary>
        /// Schedule a task for a delayed execution.
        /// </summary>
        /// <param name="task">The task to schedule.</param>
        /// <param name="delay">The delay amount.</param>
        /// <returns>The IDisposable that allows cancelling the execution of the task.</returns>
        public IDisposable Schedule(Action task, TimeSpan delay)
        {
            TestDelayedTask tt = new TestDelayedTask(task,
                                                     Now + (long)delay.TotalMilliseconds, NewId(), this, null);

            Add(tt);
            return(tt);
        }
コード例 #5
0
        /// <summary>
        /// Schedule a task for periodic execution with a fixed rate.
        /// </summary>
        /// <param name="task">The task to schedule.</param>
        /// <param name="initialDelay">The initial delay amount.</param>
        /// <param name="period">The repeat period.</param>
        /// <returns>The IDisposable that allows cancelling the execution of the task.</returns>
        public IDisposable Schedule(Action task, TimeSpan initialDelay, TimeSpan period)
        {
            TestDelayedTask tt = null;

            tt = new TestDelayedTask(() =>
            {
                task();
                tt.time += (long)period.TotalMilliseconds;
                tt.id    = NewId();
                Add(tt);
            }, Now + (long)initialDelay.TotalMilliseconds, NewId(), this, null);
            Add(tt);
            return(tt);
        }
コード例 #6
0
            public IDisposable Schedule(Action task)
            {
                if (Volatile.Read(ref disposed) != 0)
                {
                    return(EmptyDisposable.Instance);
                }
                TestDelayedTask tt = new TestDelayedTask(task, parent.Now, parent.NewId(), parent, this);

                parent.Add(tt);
                if (Volatile.Read(ref disposed) != 0)
                {
                    parent.Remove(tt);
                    return(EmptyDisposable.Instance);
                }
                return(tt);
            }
コード例 #7
0
            public IDisposable Schedule(Action task, TimeSpan delay)
            {
                if (Volatile.Read(ref disposed) != 0)
                {
                    return(EmptyDisposable.Instance);
                }
                TestDelayedTask tt = new TestDelayedTask(task,
                                                         parent.Now + (long)delay.TotalMilliseconds, parent.NewId(), parent, this);

                parent.Add(tt);
                if (Volatile.Read(ref disposed) != 0)
                {
                    parent.Remove(tt);
                    return(EmptyDisposable.Instance);
                }
                return(tt);
            }