예제 #1
0
            public Registration () {
                Scope = CancellationScope.Current;
                Scheduler = TaskScheduler.Current;

                if (Scheduler == null)
                    throw new InvalidOperationException("No implicitly active TaskScheduler on this thread.");
            }
예제 #2
0
            public Registration()
            {
                Scope     = CancellationScope.Current;
                Scheduler = TaskScheduler.Current;

                if (Scheduler == null)
                {
                    throw new InvalidOperationException("No implicitly active TaskScheduler on this thread.");
                }
            }
예제 #3
0
        private void AddChild(CancellationScope child)
        {
            if (this == Null)
            {
                return;
            }

            if (Children == null)
            {
                Children = new UnorderedList <CancellationScope>();
            }

            Children.Add(child);
        }
예제 #4
0
        public static bool TryCancelScope(this tTask task)
        {
            if (task.IsCanceled)
            {
                return(true);
            }
            else if (task.IsCompleted)
            {
                return(false);
            }

            CancellationScope scope;

            if (CancellationScope.TryGet(task, out scope))
            {
                return(scope.TryCancel());
            }

            return(false);
        }
예제 #5
0
            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();
            }
예제 #6
0
 public CancellationScopeAwaiter (CancellationScope scope)
     : this()
 {
     Scope = scope;
     IsCompleted = false;
 }
예제 #7
0
        private void AddChild (CancellationScope child) {
            if (this == Null)
                return;

            if (Children == null)
                Children = new UnorderedList<CancellationScope>();

            Children.Add(child);
        }
예제 #8
0
 public static bool TryGet (tTask task, out CancellationScope result) {
     return ScopeRegistry.TryGetValue(task, out result);
 }
예제 #9
0
 public static void Set (tTask task, CancellationScope scope) {
     ScopeRegistry.Add(task, scope);
 }
예제 #10
0
 public CancellationScopeAwaiter(CancellationScope scope)
     : this()
 {
     Scope       = scope;
     IsCompleted = false;
 }
예제 #11
0
 public static bool TryGet(tTask task, out CancellationScope result)
 {
     return(ScopeRegistry.TryGetValue(task, out result));
 }
예제 #12
0
 public static void Set(tTask task, CancellationScope scope)
 {
     ScopeRegistry.Add(task, scope);
 }