Alex Rivera | Logout

be notified when all background threadpool threads are finished

Asked 2008-12-11T08:58:57.307
10

I have a scenario when I start 3..10 threads with ThreadPool. Each thread does its job and returns to the ThreadPool. What are possible options to be notified in main thread when all background threads have finished?

Currently I'm using a homegrown method with incrementing a variable for each of created threads and decrementing it when a background thread is about to finish. This works just fine, but I was curious if there are better options.

Edit
Report

1 Answer

1

Couldn't you give each thread a distinct ManualResetEvent and have each set the event when done. Then, in the main thread you can wait on all the events passed in.

answered 2008-12-11T10:11:04.867

Your Answer