Here is the code to run 30 instances of Task
int total = socketCount; int perRun = 30; if(perRun > total) { perRun = total; } int currentLoad = 0; int index = 0; var ts = new Task[perRun]; int taskIndex = 0; while (true) { while (currentLoad < perRun) { if (index < total) { ts[taskIndex] = OpenWebSocketsSlice(index,webSockets[index++]); currentLoad++; taskIndex++; } else { break; } } taskIndex = Task.WaitAny(ts); currentLoad--; if (currentLoad == 0) { Task.WaitAll(ts); break; } }
Leave a comment