コード例 #1
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
        }
コード例 #2
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;
            }
        }
コード例 #3
0
        public IdleTimeAsyncTaskQueue(ICoreShell 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);
            }
        }
コード例 #4
0
        public IdleTimeAsyncTaskQueue(IServiceContainer services)
        {
            _services = services;
            _idleTime = services.GetService <IIdleTimeService>();

            var logicalCpuCount = Environment.ProcessorCount;
            var taskCount       = logicalCpuCount / 4;

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

            _workerTasks = new IdleTimeAsyncTask[taskCount];

            for (var i = 0; i < _workerTasks.Length; i++)
            {
                _workerTasks[i] = new IdleTimeAsyncTask(_services);
            }
        }