void Add(TestDelayedTask ttask) { lock (this) { queue.Add(ttask); } }
void Remove(TestDelayedTask ttask) { lock (this) { queue.Remove(ttask); } }
/// <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); }
/// <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); }
/// <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); }
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); }
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); }