public static void SafeQueueWorkItem(ThreadStart start)
{
lock (lockObject)
{
_threadActions.Enqueue(start);
// if we haven't spun all the threads up, create a new one
// and add it to our available threads
if (_availableThreads.Count < MaxThreads)
{
var t = new Thread(ActionConsumer);
_availableThreads.Add(t);
t.Start();
}
// pulse all waiting threads
_threadSynch.Set();
}
}