/// <summary> /// Adds a new Thread to the thread list and puts the thread in the waiting threads queue. /// </summary> /// <param name="start"></param> public void Add(ThreadStart start) { var thread = new Thread(start); lock (ThreadList) { ThreadList.Add(thread); } lock (WaitingThreads) { WaitingThreads.Enqueue(thread); } }
/// <summary> /// Runs the threads continuously as they are added to the thread list. The outside process must continuously check /// the /// IsAlive property to determine when all the threads have been run. /// </summary> public void RunAsynch() { while (!KillThreads) { lock (WaitingThreads) { if (WaitingThreads.Count != 0 && ActiveThreads < MaximumThreads) { var nextThread = WaitingThreads.Dequeue(); nextThread.Start(); } else { Thread.Sleep(1000); } } } }