Andrey Rubshtein Andrey Rubshtein - 2 years ago 93
C# Question

Can I limit the amount of System.Threading.Tasks.Task objects that run simultaneously?

I am using Task classes to do multi-threaded computation.

For example:

List<Task> taskList = new List<Task>();
for(int i=0;i<10;i++){
var task = new Task(() => Console.WriteLine("Hello from taskA."));

Is there a way to make only, let's say, 3 tasks to run at most, and the rest to wait?

Answer Source

change the MaxDegreeOfParallelism property.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download