protected void Start(Task task) { previousSuccess = task.Status == TaskStatus.RanToCompletion && task.Status != TaskStatus.Faulted; previousException = task.Exception; Task.Start(TaskManager.GetScheduler(Affinity)); RunContinuation(); }
public TaskBase(Task task) { Task = new Task(t => { var scheduler = TaskManager.GetScheduler(Affinity); RaiseOnStart(); var tk = ((Task)t); try { if (tk.Status == TaskStatus.Created && !tk.IsCompleted && ((tk.CreationOptions & (TaskCreationOptions)512) == TaskCreationOptions.None)) { tk.RunSynchronously(scheduler); } } catch (Exception ex) { Errors = ex.Message; if (!RaiseFaultHandlers(ex)) { throw; } } finally { RaiseOnEnd(); } }, task, Token, TaskCreationOptions.None); }
internal void SetFaultHandler(TaskBase handler) { Task.ContinueWith(t => handler.Start(t), Token, TaskContinuationOptions.OnlyOnFaulted, TaskManager.GetScheduler(handler.Affinity)); DependsOn?.SetFaultHandler(handler); }
protected override void Run(bool success) { base.Run(success); Token.ThrowIfCancellationRequested(); try { if (task.Status == TaskStatus.Created && !task.IsCompleted && ((task.CreationOptions & (TaskCreationOptions)512) == TaskCreationOptions.None)) { var scheduler = TaskManager.GetScheduler(Affinity); Token.ThrowIfCancellationRequested(); task.RunSynchronously(scheduler); } else { task.Wait(); } } catch (Exception ex) { if (!RaiseFaultHandlers(ex)) { throw exception; } Token.ThrowIfCancellationRequested(); } }
protected virtual void RunContinuation() { if (continuationOnSuccess != null) { //Logger.Trace($"Setting ContinueWith {Affinity} {continuation}"); Task.ContinueWith(_ => ((TaskBase)(object)continuationOnSuccess).Run(), Token, runOnSuccessOptions, TaskManager.GetScheduler(continuationOnSuccess.Affinity)); } if (continuationOnFailure != null) { //Logger.Trace($"Setting ContinueWith {Affinity} {continuation}"); Task.ContinueWith(_ => ((TaskBase)(object)continuationOnFailure).Run(), Token, runOnFaultOptions, TaskManager.GetScheduler(continuationOnFailure.Affinity)); } if (continuationOnAlways != null) { //Logger.Trace($"Setting ContinueWith {Affinity} {continuation}"); Task.ContinueWith(_ => ((TaskBase)(object)continuationOnAlways).Run(), Token, runAlwaysOptions, TaskManager.GetScheduler(continuationOnAlways.Affinity)); } }
protected virtual void RunContinuation() { if (continuation != null) { //Logger.Trace($"Setting ContinueWith {Affinity} {continuation}"); Task.ContinueWith(_ => ((TaskBase)(object)continuation).Run(), Token, continuationAlways ? runAlwaysOptions : runOnSuccessOptions, TaskManager.GetScheduler(continuation.Affinity)); } }
protected void SetContinuation(TaskBase continuation, TaskContinuationOptions runOptions) { Token.ThrowIfCancellationRequested(); Task.ContinueWith(_ => { Token.ThrowIfCancellationRequested(); ((TaskBase)(object)continuation).Schedule(); }, Token, runOptions, TaskManager.GetScheduler(continuation.Affinity)); }
/// <summary> /// This does not set a dependency between the two tasks. Instead, /// the Start method grabs the state of the previous task to pass on /// to the next task via previousSuccess and previousException /// </summary> /// <param name="handler"></param> internal void SetFaultHandler(TaskBase handler) { Task.ContinueWith(t => { Token.ThrowIfCancellationRequested(); handler.Start(t); }, Token, TaskContinuationOptions.OnlyOnFaulted, TaskManager.GetScheduler(handler.Affinity)); DependsOn?.SetFaultHandler(handler); }
protected void SetContinuation(TaskBase continuation, TaskContinuationOptions runOptions) { Task.ContinueWith(_ => ((TaskBase)(object)continuation).Run(), Token, runOptions, TaskManager.GetScheduler(continuation.Affinity)); }