I'm looking into creating tasks which need to be executed on multiple threads. I could have a large number of tasks being created i.e. 2000 for example. I want to limit the number of tasks queued and executed simultaneously. Is there a way to create a certain number of tasks and then create new ones as they complete? Trying to work out if the task scheduler helps with this.
EDIT:
To phrase this a different way...is there a reason I should want to limit the number of tasks created/queued/executed simultaneously given that I could have a really large number e.g. 2000. Does the task scheduler optimally schedule tasks, can't seem to find any info on how it actually works...
EDIT:
I'm not using Parallel.Foreach. I've decided to use counters and based on a max number of counters, and the current number of tasks, create tasks or wait until the max number is not exceeded.