/// <summary>
 /// Schedules a task.
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public TaskQueue Schedule(Action<TaskContext, CancellationToken> action)
 {
     var context = new TaskContext(this, async (q, ct) => action(q, ct));
     ScheduleInternal(context);
     return this;
 }
 /// <summary>
 /// Schedules a task.
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 public TaskQueue Schedule(string tag, Func<TaskContext, CancellationToken, Task> action)
 {
     var context = new TaskContext(this, action, tag);
     ScheduleInternal(context);
     return this;
 }
 /// <summary>
 /// Schedules a task.
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="task"></param>
 /// <returns></returns>
 public TaskQueue Schedule(string tag, Task task)
 {
     var context = new TaskContext(this, async (q, ct) => await task);
     ScheduleInternal(context);
     return this;
 }
 private void ScheduleInternal(TaskContext context)
 {
     queue.Enqueue(context);
     TaskScheduled?.Invoke(this, new TaskEventArgs(context.Tag));
     Next(cts.Token);
 }
 private void ScheduleInternal(TaskContext context)
 {
     queue.Enqueue(context);
     TaskScheduled?.Invoke(this, new TaskEventArgs(context.Tag));
     Next(cts.Token);
 }