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 }
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(); } }
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); } }
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; } }
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(); } }
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); } }
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 }
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; } }