private void EnsureWorker() { if (smtpWorkerPool.Count < maxConnections) { bool anyIdle = false; foreach (var worker in smtpWorkerPool) { if (worker.IsIdle) { anyIdle = true; break; } } if (!anyIdle) { var newWorker = new SmtpWorker(this); smtpWorkerPool.Add(newWorker); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:mm':'ss.ffffff}: EnsureWorker, pool count = {1}, queue length = {2}", DateTimeOffset.Now, smtpWorkerPool.Count, messageQueue.Count)); newWorker.Start(); } } }