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
}
}