public Registration(IWorkItemQueueTarget scheduler) { Scope = CancellationScope.Current; Scheduler = scheduler; if ((Scheduler == null) && StrictMode) { throw new InvalidOperationException("No implicitly active TaskScheduler on this thread."); } }
private void AddChild(CancellationScope child) { if (this == Null) { return; } if (Children == null) { Children = new UnorderedList <CancellationScope>(); } Children.Add(child); }
public void OnCompleted(Action continuation) { CancellationUtil.UnpackContinuation(continuation, out Scope.Task); CancellationScope existingScope; if (CancellationScope.TryGet(Scope.Task, out existingScope)) { // HACK: In some cases a cancelled task will get resumed, which starts it over from the beginning. // This hits us and we will get asked to schedule a resume, but we should ignore it so that the task // stays dead as it should. #if TRACING Console.WriteLine("Rejecting attempted resurrection of task {0}", existingScope); #endif return; } CancellationScope.Set(Scope.Task, Scope); IsCompleted = true; continuation(); }
public static bool TryGet(tTask task, out CancellationScope result) { return(ScopeRegistry.TryGetValue(task, out result)); }
public static void Set(tTask task, CancellationScope scope) { ScopeRegistry.Add(task, scope); }
public CancellationScopeAwaiter(CancellationScope scope) : this() { Scope = scope; IsCompleted = false; }