예제 #1
0
 public void SetCanceled()
 {
     if (!ApplyOperation(TaskStatus.Canceled, () => { source.Cancel(); source.CancelReal(); }))
     {
         ThrowInvalidException();
     }
 }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
파일: Task.cs 프로젝트: raj581/Marvin
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
 static void SetCanceledAction(Task <TResult> source, object unused)
 {
     source.CancelReal();
 }