"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:wb*****************@newsread3.news.pas.earthl ink.net...
If I use standard Threading.Thread threads, I can issue a Join on the
thread
variable and wait for it to complete. How can I do this on the Background
Worker Threads in a threadpool without looping. Basically, I will be
queuing an unknown number of worker threads in the pool and I need to wait
for them all to complete.
Pool threads never exit or they wouldn't be in the pool. Consequently you
cannot Join with them.
See WaitHandle.WaitAll
NB. It is crucial when using pool threads that you don't throw an exception
out of your delegate without signalling that it has exited (unlike Join
where you will get to know) therefore the delegate should ALWAYS be a
try...catch...finally block.
Ideally you use some sort of shared object to store the completion state,
initialize it to "software messed up" at the top of the try block, set it to
"success" at the bottom, set it to sepcific errors in the catch and signal
completion in the finally block.