Asynchronous task that start on next idle slot
Inheritance: IDisposable
示例#1
0
        private static bool GetAvailableTask(object tag, out IdleTimeAsyncTask worker)
        {
            // Ensure no current workers are processing work items with the same tag.
            // This ensures object thread affinity so no two HTML validators
            // will run in the same document.

            worker = null;
            bool thisTagIsRunning = false;

            for (int i = 0; i < _workerTasks.Length; i++)
            {
                var candidate = _workerTasks[i];

                if (candidate.TaskRunning && candidate.Tag == tag)
                {
                    // Task with this tag is already running, try another task maybe
                    thisTagIsRunning = true;
                }
                else if (!candidate.TaskRunning)
                {
                    worker = candidate;
                }
            }

            bool workerAvailable = worker != null;

            if (thisTagIsRunning)
            {
                worker = null;       // worker is available but not for this task
            }
            return(workerAvailable); // some task is available
        }
示例#2
0
        protected OutlineRegionBuilder(ITextBuffer textBuffer, IEditorShell editorShell) {
            CurrentRegions = new OutlineRegionCollection(0);

            TextBuffer = textBuffer;
            TextBuffer.Changed += OnTextBufferChanged;

            BackgroundTask = new IdleTimeAsyncTask(TaskAction, MainThreadAction, editorShell);
            if (IsEnabled) {
                BackgroundTask.DoTaskOnIdle(300);
            }
        }
        protected OutlineRegionBuilder(ITextBuffer textBuffer) {
            CurrentRegions = new OutlineRegionCollection(0);

            TextBuffer = textBuffer;
            TextBuffer.Changed += OnTextBufferChanged;

            // Unit test case
            if (EditorShell.IsUIThread) {
                BackgroundTask = new IdleTimeAsyncTask(TaskAction, MainThreadAction);
                BackgroundTask.DoTaskOnIdle(300);
            }
        }
        static IdleTimeAsyncTaskQueue() {
            var logicalCpuCount = Environment.ProcessorCount;

            var taskCount = logicalCpuCount / 4;
            if (taskCount == 0)
                taskCount = 1;

            _workerTasks = new IdleTimeAsyncTask[taskCount];

            for (int i = 0; i < _workerTasks.Length; i++) {
                _workerTasks[i] = new IdleTimeAsyncTask();
            }
        }
示例#5
0
        public IdleTimeAsyncTaskQueue(IEditorShell shell) {
            _shell = shell;
            var logicalCpuCount = Environment.ProcessorCount;

            var taskCount = logicalCpuCount / 4;
            if (taskCount == 0)
                taskCount = 1;

            _workerTasks = new IdleTimeAsyncTask[taskCount];

            for (int i = 0; i < _workerTasks.Length; i++) {
                _workerTasks[i] = new IdleTimeAsyncTask(_shell);
            }
        }
示例#6
0
        private static void DisconnectFromIdle()
        {
            if (_connectedToIdle)
            {
                _connectedToIdle = false;

                // We're holding onto these tasks in a static, let's clean them up
                //   Otherwise, they could be pointing to closed documents/views
                //   or other stale data that the Tag or callbacks hold onto.
                for (int i = 0; i < _workerTasks.Length; i++)
                {
                    _workerTasks[i] = new IdleTimeAsyncTask();
                }

                EditorShell.Current.Idle -= OnIdle;
            }
        }
示例#7
0
        static IdleTimeAsyncTaskQueue()
        {
            var logicalCpuCount = Environment.ProcessorCount;

            var taskCount = logicalCpuCount / 4;

            if (taskCount == 0)
            {
                taskCount = 1;
            }

            _workerTasks = new IdleTimeAsyncTask[taskCount];

            for (int i = 0; i < _workerTasks.Length; i++)
            {
                _workerTasks[i] = new IdleTimeAsyncTask();
            }
        }
示例#8
0
        public IdleTimeAsyncTaskQueue(IEditorShell shell)
        {
            _shell = shell;
            var logicalCpuCount = Environment.ProcessorCount;

            var taskCount = logicalCpuCount / 4;

            if (taskCount == 0)
            {
                taskCount = 1;
            }

            _workerTasks = new IdleTimeAsyncTask[taskCount];

            for (int i = 0; i < _workerTasks.Length; i++)
            {
                _workerTasks[i] = new IdleTimeAsyncTask(_shell);
            }
        }
示例#9
0
        private bool GetAvailableTask(object tag, out IdleTimeAsyncTask worker) {
            // Ensure no current workers are processing work items with the same tag.
            // This ensures object thread affinity so no two HTML validators 
            // will run in the same document.

            worker = null;
            bool thisTagIsRunning = false;

            for (int i = 0; i < _workerTasks.Length; i++) {
                var candidate = _workerTasks[i];

                if (candidate.TaskRunning && candidate.Tag == tag) {
                    // Task with this tag is already running, try another task maybe
                    thisTagIsRunning = true;
                } else if (!candidate.TaskRunning) {
                    worker = candidate;
                }
            }

            bool workerAvailable = worker != null;

            if (thisTagIsRunning)
                worker = null; // worker is available but not for this task

            return workerAvailable; // some task is available
        }
示例#10
0
        private void DisconnectFromIdle() {
            if (_connectedToIdle) {
                _connectedToIdle = false;

                // We're holding onto these tasks in a static, let's clean them up
                //   Otherwise, they could be pointing to closed documents/views
                //   or other stale data that the Tag or callbacks hold onto.
                for (int i = 0; i < _workerTasks.Length; i++) {
                    _workerTasks[i] = new IdleTimeAsyncTask(_shell);
                }

                _shell.Idle -= OnIdle;
            }
        }