/// <summary> /// Run a Job /// </summary> /// <param name="job">job to run</param> /// <returns>true</returns> public bool Dispatch(ThreadStart job) { if (!IsRunning || job == null) { return(false); } ThreadPoolWorker thread = null; bool spawn = false; // Look for an idle thread thread = _idleQue.Dequeue(); if (thread == null) { // queue the job int count = _jobsQue.Enqueue(job); lock (_lock) { //int count = _jobsQue.Count; if (count > _maxQueued) { _maxQueued = count; } } spawn = count > _spawnOrShrinkAt; if (spawn) { NewThread(); } } else { // assign the job to the selected thread thread.Dispatch(job); } return(true); }