Exemplo n.º 1
0
 protected virtual Task OnErrorAsync(HTaskSchedularErrorEventArgs e)
 {
     if (e == null)
     {
         return(Task.CompletedTask);
     }
     return(Cancellable.CancellableRunAsync(
                () => Error?.Invoke(e.Sender, e)
                , this.Cts.Token));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Start monitoring scheduled tasks in order to trigger IsTaskDue event when tasks are ready for execution.
 /// </summary>
 /// <param name="cancellationToken">If provided, the monitoring force stops all running tasks</param>
 /// <returns>a running monitoring task</returns>
 public Task Start(CancellationToken?cancellationToken = null)
 {
     if (!this.RunSwitch.TryOpen())
     {
         return(Task.CompletedTask);
     }
     //this.Load();
     this.Cts = cancellationToken == null
         ? new CancellationTokenSource()
         : CancellationTokenSource.CreateLinkedTokenSource(
         (CancellationToken)cancellationToken);
     return(Cancellable.CancellableRunAsync(MonitorTasks, this.Cts.Token));
 }
Exemplo n.º 3
0
 private void MonitorTasks()
 {
     while (!this.Cts.IsCancellationRequested)
     {
         foreach (var task in this.Tasks)
         {
             Cancellable.CancellableRunAsync(() =>
             {
                 this.ThreadTraffic.QueueCall(() =>
                 {
                     Process(task);
                 }, 0, task.UniqueKey);
             }, this.Cts.Token);
         }
         Task.Delay(this.TickInterval, this.Cts.Token).GetAwaiter().GetResult();
     }
 }