Exemple #1
0
        private static void NestIterator(ITask currentTask)
        {
            ITask   t = currentTask;
            Handler arbiterCleanup = t.ArbiterCleanupHandler;

            t.ArbiterCleanupHandler = delegate
            {
                t.ArbiterCleanupHandler = arbiterCleanup;
                TaskExecutionWorker.ExecuteTask(ref t, t.TaskQueue, true);
            };
            currentTask.TaskQueue.Enqueue(t);
        }
Exemple #2
0
        private void AddWorker(ThreadPriority priority, ApartmentState apartmentState, int maxThreadStackSize)
        {
            TaskExecutionWorker taskExecutionWorker = new TaskExecutionWorker(this);
            Thread thread = new Thread(new ThreadStart(taskExecutionWorker.ExecutionLoop), maxThreadStackSize);

            thread.SetApartmentState(apartmentState);
            thread.Name                 = _name;
            thread.Priority             = priority;
            thread.IsBackground         = (DispatcherOptions.None < (_options & DispatcherOptions.UseBackgroundThreads));
            taskExecutionWorker._thread = thread;
            _taskExecutionWorkers.Add(taskExecutionWorker);
            _cachedWorkerListCount++;
        }
Exemple #3
0
 internal void Signal()
 {
     if (_cachedWorkerListCount == 0)
     {
         Dispatcher.LogError("Dispatcher disposed, will not schedule task", new ObjectDisposedException("Dispatcher"));
         return;
     }
     Interlocked.Increment(ref _pendingTaskCount);
     for (int i = 0; i < _cachedWorkerListCount; i++)
     {
         TaskExecutionWorker taskExecutionWorker = _taskExecutionWorkers[i];
         if (taskExecutionWorker.Signal())
         {
             return;
         }
     }
 }
Exemple #4
0
        public static void ExecuteInCurrentThreadContext(object t)
        {
            ITask task = (ITask)t;

            try
            {
                TaskExecutionWorker.ExecuteTask(ref task, task.TaskQueue, false);
                Dispatcher.SetCurrentThreadCausalities(null);
            }
            catch (Exception ex)
            {
                if (TaskExecutionWorker.IsCriticalException(ex))
                {
                    throw;
                }
                TaskExecutionWorker.HandleException(task, ex);
            }
        }
Exemple #5
0
        private static void ExecuteTask(ref ITask currentTask, DispatcherQueue p, bool bypassExecute)
        {
            Handler         arbiterCleanupHandler = currentTask.ArbiterCleanupHandler;
            IteratorContext iteratorContext;

            if (bypassExecute)
            {
                iteratorContext = null;
            }
            else
            {
                iteratorContext = TaskExecutionWorker.ExecuteTaskHelper(currentTask);
            }
            if (iteratorContext == null)
            {
                iteratorContext = (IteratorContext)currentTask.LinkedIterator;
            }
            if (iteratorContext != null)
            {
                Dispatcher.SetCurrentThreadCausalities(iteratorContext._causalities);
                TaskExecutionWorker.MoveIterator(ref currentTask, iteratorContext, ref arbiterCleanupHandler);
                if (currentTask != null)
                {
                    currentTask.LinkedIterator = iteratorContext;
                    currentTask.TaskQueue      = p;
                    iteratorContext            = TaskExecutionWorker.ExecuteTaskHelper(currentTask);
                    if (iteratorContext != null)
                    {
                        TaskExecutionWorker.NestIterator(currentTask);
                    }
                }
            }
            if (arbiterCleanupHandler != null)
            {
                if (currentTask != null)
                {
                    currentTask.ArbiterCleanupHandler = null;
                }
                arbiterCleanupHandler();
            }
        }
Exemple #6
0
        internal void ExecutionLoop()
        {
            CheckStartupComplete();
            while (true)
            {
IL_06:
                int num = 0;
                int   num2        = 0;
                ITask currentTask = null;
                try
                {
                    bool flag = false;
                    while (true)
                    {
                        if (num == 0)
                        {
                            if (_thread == null)
                            {
                                break;
                            }
                            WaitForTask(flag);
                        }
                        num2++;
                        num = 0;
                        int cachedDispatcherQueueCount = _dispatcher._cachedDispatcherQueueCount;
                        for (int i = 0; i < cachedDispatcherQueueCount; i++)
                        {
                            if (cachedDispatcherQueueCount != _dispatcher._cachedDispatcherQueueCount)
                            {
                                goto Block_5;
                            }
                            DispatcherQueue dispatcherQueue;
                            try
                            {
                                dispatcherQueue = _dispatcher._dispatcherQueues[(i + num2) % cachedDispatcherQueueCount];
                            }
                            catch
                            {
                                goto IL_06;
                            }
                            if (_isFastTimerLogicEnabled)
                            {
                                flag |= dispatcherQueue.CheckTimerExpirations();
                            }
                            if (dispatcherQueue.TryDequeue(out currentTask))
                            {
                                num += dispatcherQueue.Count;
                                TaskExecutionWorker.ExecuteTask(ref currentTask, dispatcherQueue, false);
                            }
                        }
                    }
                    Dispatcher.ClearCausalities();
                    CheckShutdownComplete();
                    Dispatcher.ClearCausalities();
                    break;
Block_5:
                    continue;
                }
                catch (Exception ex)
                {
                    if (TaskExecutionWorker.IsCriticalException(ex))
                    {
                        throw;
                    }
                    TaskExecutionWorker.HandleException(currentTask, ex);
                    continue;
                }
            }
        }
Exemple #7
0
 public static void ExecuteNow(DispatcherQueue dispatcherQueue, ITask task)
 {
     task.TaskQueue = dispatcherQueue;
     TaskExecutionWorker.ExecuteInCurrentThreadContext(task);
 }