internal static bool NotifyThreadIdle(ThreadPoolThread thread) { lock (_Threads) { if (_Threads.Count > _maxThreadCount) { thread.Dispose(); _Threads.Remove(thread); Debug.WriteLine(string.Concat("ThreadPool | ", DateTime.Now.ToString("MM/dd/yyyy | HH:mm:ss.fff"), " | Thread stopped: #" + _Threads.Count)); return(false); } } // start next enqueued item lock (_ItemsQueue.SyncRoot) { if (_ItemsQueue.Count > 0) { thread.Item = _ItemsQueue.Dequeue() as ThreadPoolItem; return(true); } } return(false); }
private static ThreadPoolThread GetThread() { lock (_Threads) { foreach (ThreadPoolThread thread in _Threads) { if (!thread.IsBusy) { thread.IsBusy = true; return(thread); } } if (_Threads.Count < _maxThreadCount) { var thread = new ThreadPoolThread { IsBusy = true }; _Threads.Add(thread); return(thread); } return(null); } }