public void RemoveWorker(WorkerThread worker) { lock (_workersLock) { _log("Removing worker " + worker.Id()); _workers.Remove(worker); } }
private void _scale(int count) { _log("Scaling " + count); if (count > 0) { for (int i = 0; i < count; i++) { if (_workers.Count >= MaxWorkerThreads) { return; } WorkerThread worker = new WorkerThread(this); _workers.Add(worker); _log("Starting worker " + worker.Id()); worker.Start(); } } else { for (int i = 0; i < -count; i++) { if (_workers.Count <= MinWorkerThreads) { return; } WorkerThread worker = null; try { worker = _workers.ElementAt(i); } catch (Exception e) { } if (worker == null) { break; } _log("Stopping worker " + worker.Id()); worker.Stop(); } } }
public void Shutdown(bool wait = true) { for (int i = 0; i < _workers.Count; i++) { WorkerThread worker = null; try { worker = _workers.ElementAt(i); } catch (Exception e) { } if (worker == null) { break; } _log("Stopping worker " + worker.Id() + " due to shutdown"); worker.Stop(); } if (wait) { while (_workers.Count() > 0) { Thread.Sleep(1); } } }