Ejemplo n.º 1
0
        internal bool InternalStart(TaskScheduler scheduler, bool inline, bool throwSchedulerExceptions)
        {
            ExecutingTaskScheduler = scheduler;
            var result = Interlocked.CompareExchange(ref _status, (int)TaskStatus.WaitingForActivation, (int)TaskStatus.Created);

            if (result != (int)TaskStatus.Created && result != (int)TaskStatus.WaitingForActivation)
            {
                return(false);
            }
            var didInline = false;

            try
            {
                if (inline)
                {
                    // Should I worry about this task being a continuation?
                    // WaitAntecedent(CancellationToken);
                    didInline = scheduler.InernalTryExecuteTaskInline(this, IsScheduled);
                }
                if (!didInline)
                {
                    scheduler.QueueTask(this);
                    Interlocked.CompareExchange(ref _status, (int)TaskStatus.WaitingToRun, (int)TaskStatus.WaitingForActivation);
                }
                else
                {
                    PrivateWait(CancellationToken, false);
                }
            }
            catch (ThreadAbortException exception)
            {
                if (!didInline)
                {
                    AddException(exception);
                    FinishThreadAbortedTask(true, false);
                }
            }
            catch (Exception exception)
            {
                var taskSchedulerException = new TaskSchedulerException(exception);
                RecordException(taskSchedulerException);
                if (throwSchedulerExceptions)
                {
                    throw taskSchedulerException;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
 private void RecordException(TaskSchedulerException taskSchedulerException)
 {
     AddException(taskSchedulerException);
     Finish(false);
     if ((_internalOptions & InternalTaskOptions.ContinuationTask) != 0)
     {
         return;
     }
     if (_exceptionsHolder != null)
     {
         Contract.Assert(_exceptionsHolder.ContainsFaultList, "Expected _exceptionsHolder to have faults recorded.");
         _exceptionsHolder.MarkAsHandled(false);
     }
     else
     {
         Contract.Assert(false, "Expected _exceptionsHolder to exist.");
     }
 }