Esempio n. 1
0
        public void Execute(Task completedTask)
        {
            completedTask.RemoveContinuation(this);

            if (completedTask.IsFaulted)
            {
                if (exceptions == null)
                {
                    Interlocked.CompareExchange(ref exceptions, new ConcurrentLinkedQueue <Exception>(), null);
                }
                exceptions.Add(completedTask.Exception);
            }
            else if (completedTask.IsCanceled)
            {
                canceled = true;
            }

            bool isComplete = Interlocked.Decrement(ref counter) == 0;

            if (!isComplete)
            {
                return;
            }

            if (exceptions != null)
            {
                owner.SetException(exceptions.AsEnumerable());
                return;
            }

            if (canceled)
            {
                owner.SetCanceled();
                return;
            }

            owner.SetResult(null);
        }