Esempio n. 1
0
        private void Execute(object state)
        {
            var previousSynchronizationContext = PrepareThreadForExecute();
            var actorTask           = (ActorTask)state;
            var onLongRunningThread = (actorTask.Task.CreationOptions & TaskCreationOptions.LongRunning) == TaskCreationOptions.LongRunning;
            var switchThreadType    = false;

            while (!(actorTask is null) && !switchThreadType)
            {
                var task           = actorTask.Task;
                var isTerminalTask = (actorTask.Traits & ActorTaskTraits.Terminal) != 0;

                TryExecuteTask(task);

                actorTask.CleanUpPostExecute();

                var shouldTerminate = isTerminalTask || (actorTask.Traits & ActorTaskTraits.Critical) != 0 && task.Status != TaskStatus.RanToCompletion;

                actorTask = null;

                TakeLock();

                if (shouldTerminate)
                {
                    _status = ActorTaskSchedulerStatus.Terminated;
                    ReleaseLock();
                    TerminationCleanUp(isTerminalTask ? task : null);
                }
                else if (_shouldPause && (_front is null || (_front.Traits & ActorTaskTraits.Resuming) == 0))
                {
                    _status = ActorTaskSchedulerStatus.Paused;
                    ReleaseLock();
                }
Esempio n. 2
0
        private void QueueTask(ActorTask actorTask)
        {
            TakeLock();

            switch (_status)
            {
            case ActorTaskSchedulerStatus.Terminated:
                ReleaseLock();
                CancelActorTask(actorTask);
                break;

            case ActorTaskSchedulerStatus.Inactive:
                _status = ActorTaskSchedulerStatus.Active;
                ReleaseLock();
                QueueForExecution(actorTask);
                break;

            case ActorTaskSchedulerStatus.Active:
                if ((actorTask.Traits & ActorTaskTraits.Resuming) == ActorTaskTraits.Resuming)
                {
                    actorTask.Next = _front;
                    _front         = actorTask;

                    if (_back is null)
                    {
                        _back = _front;
                    }
                }
                else
                {
                    if (_front is null)
                    {
                        _front = actorTask;
                    }
                    else
                    {
                        _back.Next = actorTask;
                    }

                    _back = actorTask;
                }

                ReleaseLock();

                break;

            case ActorTaskSchedulerStatus.Paused:
                if ((actorTask.Traits & ActorTaskTraits.Resuming) == ActorTaskTraits.Resuming)
                {
                    _status = ActorTaskSchedulerStatus.Active;
                    ReleaseLock();
                    QueueForExecution(actorTask);
                }
                else
                {
                    if (_front is null)
                    {
                        _front = actorTask;
                    }
                    else
                    {
                        _back.Next = actorTask;
                    }

                    _back = actorTask;
                    ReleaseLock();
                }

                break;
            }
        }