public void SetCanceled() { if (!ApplyOperation(TaskStatus.Canceled, () => { source.Cancel(); source.CancelReal(); })) { ThrowInvalidException(); } }
void CompletionExecutor(Task cont) { if (cont.Slot.Predicate != null && !cont.Slot.Predicate()) { return; } if (!cont.Slot.Launched.TryRelaxedSet()) { return; } if (!ContinuationStatusCheck(cont.Slot.Kind)) { cont.CancelReal(); cont.Dispose(); return; } if ((cont.Slot.Kind & TaskContinuationOptions.ExecuteSynchronously) != 0) { cont.RunSynchronously(cont.scheduler); } else { cont.Schedule(); } }
internal void ContinueWithCore(Task continuation, TaskContinuationOptions kind, TaskScheduler scheduler, Func <bool> predicate) { // Already set the scheduler so that user can call Wait and that sort of stuff continuation.scheduler = scheduler; continuation.schedWait.Set(); continuation.status = TaskStatus.WaitingForActivation; AtomicBoolean launched = new AtomicBoolean(); EventHandler action = delegate(object sender, EventArgs e) { if (launched.TryRelaxedSet()) { if (!predicate()) { return; } if (!ContinuationStatusCheck(kind)) { continuation.CancelReal(); continuation.Dispose(); return; } CheckAndSchedule(continuation, kind, scheduler, sender == null); } }; if (IsCompleted) { action(null, EventArgs.Empty); return; } if (completed == null) { Interlocked.CompareExchange(ref completed, new ConcurrentQueue <EventHandler> (), null); } completed.Enqueue(action); // Retry in case completion was achieved but event adding was too late if (IsCompleted) { action(null, EventArgs.Empty); } }
public void Execute() { if (Interlocked.Decrement(ref counter) != 0) { return; } owner.Status = TaskStatus.Running; bool canceled = false; List <Exception> exceptions = null; foreach (var task in tasks) { if (task.IsFaulted) { if (exceptions == null) { exceptions = new List <Exception> (); } exceptions.AddRange(task.Exception.InnerExceptions); continue; } if (task.IsCanceled) { canceled = true; } } if (exceptions != null) { owner.TrySetException(new AggregateException(exceptions), false, false); return; } if (canceled) { owner.CancelReal(); return; } owner.Finish(); }
internal void ContinueWithCore(Task continuation, TaskContinuationOptions kind, TaskScheduler scheduler, Func <bool> predicate) { // Already set the scheduler so that user can call Wait and that sort of stuff continuation.taskScheduler = scheduler; continuation.scheduler = ProxifyScheduler(scheduler); AtomicBoolean launched = new AtomicBoolean(); EventHandler action = delegate { if (!predicate()) { return; } if (!launched.Value && !launched.Exchange(true)) { if (!ContinuationStatusCheck(kind)) { continuation.Cancel(); continuation.CancelReal(); continuation.Dispose(); return; } CheckAndSchedule(continuation, kind, scheduler); } }; if (IsCompleted) { action(this, EventArgs.Empty); return; } completed += action; // Retry in case completion was achieved but event adding was too late if (IsCompleted) { action(this, EventArgs.Empty); } }
void CompletionExecutor(Task cont) { if (cont.Slot.Predicate != null && !cont.Slot.Predicate()) { return; } if (!cont.Slot.Launched.TryRelaxedSet()) { return; } if (!ContinuationStatusCheck(cont.Slot.Kind)) { cont.CancelReal(); cont.Dispose(); return; } CheckAndSchedule(cont, cont.Slot.Kind, cont.scheduler, false); }
public void Execute() { if (!ContinuationStatusCheck(continuationOptions)) { task.CancelReal(notifyParent: true); task.Dispose(); return; } if (task.IsCompleted) { return; } if ((continuationOptions & TaskContinuationOptions.ExecuteSynchronously) != 0) { task.RunSynchronouslyCore(task.scheduler, false); } else { task.Schedule(false); } }
public void Execute() { if (!ContinuationStatusCheck(continuationOptions)) { task.CancelReal(); task.Dispose(); return; } // The task may have been canceled externally if (task.IsCompleted) { return; } if ((continuationOptions & TaskContinuationOptions.ExecuteSynchronously) != 0) { task.RunSynchronouslyCore(task.scheduler, false); } else { task.Schedule(false); } }
static void SetCanceledAction(Task <TResult> source, object unused) { source.CancelReal(); }