Wait for threadpool to finish


  • I want to have a ThreadPool of "worker" threads that wait to be signaled to work. Once signaled it does its work then loop back to beginning and waits to be signaled again. I know how to use manual and auto resetevents to signal the thread. The only way I can see to accomplish this is to use an AutoResetEvent to toggle each thread to do work and hold for more work and use a for loop to in the main thread to call Join() on all threads. This doesn't seem elegant. Any suggestions?


    To elaborate, I know I can use the AutoResetEvent I pass into the thread, internally, to signal the main thread , which is using WaitAll on the collection of passed in AutoResetEvents, I've exited. However, I want to have the thread to initially wait until signaled to start and then loop back to the beginning to wait to be signaled again. Also, is this a good paradigm? Would it be better to not have a looping thread like this and just que a new thread in the main thread if the same work needed to be done?

    Thursday, September 23, 2010 5:10 AM