i am trying to simplify problem as follows,
Now my problem is i would like to make sure that only 5 threads are spawn at a time as starting 100 + threads is not good idea at all.
So please tell me what approach i should use to ensure that the only 5 threads are working at time and as soon as even one of them is done new one can be started.
Thanks all,
I vote for the task parallel library / Rx (included in .NET 4.0, but downloadable for 3.5):
var options = new ParallelOptions();
options.MaxDegreeOfParallelism = 5;
Parallel.ForEach(GetListOFiles(), options, (file) =>
{
DoStuffWithFile(file);
});
Note that this will use up to 5 threads, but I've seen it use less.
You should take a look at the
system.threading.threadpool.setmaxthreads
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With