QueueTask() protected abstract method

protected abstract QueueTask ( System.Threading.Tasks.Task task ) : void
task System.Threading.Tasks.Task
return void
Esempio 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.InternalTryExecuteTaskInline(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)
                {
                    return(true);
                }

                AddException(exception);
                FinishThreadAbortedTask(true, false);
            }
            catch (Exception exception)
            {
                var taskSchedulerException = new TaskSchedulerException(exception);
                RecordException(taskSchedulerException);
                if (throwSchedulerExceptions)
                {
                    throw taskSchedulerException;
                }
            }

            return(true);
        }
Esempio n. 2
0
		internal void Schedule ()
		{
			Status = TaskStatus.WaitingToRun;
			
			// If worker is null it means it is a local one, revert to the old behavior
			// If TaskScheduler.Current is not being used, the scheduler was explicitly provided, so we must use that
			if (scheduler != TaskScheduler.Current || childWorkAdder == null || HasFlag (creationOptions, TaskCreationOptions.PreferFairness)) {
				scheduler.QueueTask (this);
			} else {
				/* Like the semantic of the ABP paper describe it, we add ourselves to the bottom 
				 * of our Parent Task's ThreadWorker deque. It's ok to do that since we are in
				 * the correct Thread during the creation
				 */
				childWorkAdder (this);
			}
		}
Esempio n. 3
0
 public void AddWork(Task t)
 {
     scheduler.QueueTask(t);
 }
Esempio n. 4
0
 internal void Schedule()
 {
     status = TaskStatus.WaitingToRun;
     scheduler.QueueTask(this);
 }
Esempio n. 5
0
 private bool PrivateStart(TaskScheduler scheduler, bool inline, bool throwSchedulerExceptions)
 {
     Scheduler = 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)
         {
             didInline = scheduler.TryExecuteTaskInline(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;
 }