Threading

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

I'm wanting a loop that executes threads via BeginInvoke. The user can
control the number of threads they want, on the fly. Anybody know a good
scheme on how to do this? I was using the Interlocked class to increment
when I call BeginInvoke and a decrement when the thread was done, to know
when all of the threads are done executing, and the ammount of current
threads. This appears to fail sometimes, therefore I'm looking for a
different logic model. Any help would be great.

JB
 
You could use the threadpool and let it manage the number of threads for
you. It was designed specifically to manage the number of threads, and also
handles details that most people would find it difficult to get correct,
such as thread decay, security, etc. If you don't like the runtime's
implementation there are plenty of code samples around the internet that you
could use as the basis of your own.
 
Back
Top