Simulate Thread.Join

M

Michael D. Ober

In the non-pooled System.Threading.Thread class, there is a Join method that
will wait until the thread is complete. How can I easily simulate this
using the thread pool. Basically, I have an application that, given it's
druthers, would generate over 300 threads, but because of resource
limitations, 10 to 15 is a realistic maximum before thread contention
becomes an issue. I know I can control the number of worker threads in the
thread pool, but I don't know how to detect that all the threads (or for
that matter, any specific thread) is complete. I need something akin to
Thread.Join.

Thanks,
Mike.
 
M

Michael D. Ober

Can I add to the array while it's being waited on? My problem domain
involves walking directories on a remote system and I don't know how many
threads will be created on any given run.

Mike.
 
M

Michael D. Ober

What I ended up doing was creating a application global Semaphore with the
initial count and maximum count the same. Then at the beginning of each
thread I did a waitone on the semaphore. At the end of the thread
processing, I did a Release on the semaphore. This results in a lot of
threads being created (my test run created over 300 threads), but only a few
in a running state at any given time with the rest waiting on the semaphore.
The specific order the threads run was immaterial to this application - just
that they all run.

Thanks,
Mike.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top