private void ShutDownThread()
{
//Let the manager know that it is done with its 'task'!
if (Interlocked.Decrement(ref manager.tasksRemaining) == 0)
{
if (!manager.disposed) //Don't mess with the handle if it's already disposed.
manager.allThreadsIdleNotifier.Set();
}
//Dump out any remaining tasks in the queue.
for (int i = 0; i < taskQueue.Count; i++) //This is still safe since shutDownThread is called from within a lock(taskQueue) block.
{
taskQueue.Dequeue();
if (Interlocked.Decrement(ref manager.tasksRemaining) == 0)
{
if (!manager.disposed) //Don't mess with the handle if it's already disposed.
manager.allThreadsIdleNotifier.Set();
}
}
lock (manager.workers)
manager.workers.Remove(this);
}