Running Tasks in parallel is very simple, the collection of tasks below return a string and its workload is simply to create a text file and then delay for x milliseconds to mimic a longer workload.
The complete code for these snippets is at https://github.com/carlpaton/ThreadingDemo/tree/main/src/RunTasksInParallel
var millisecondsTimeout = 2000;
Create the service that does some work and has the mimic of a longer workload.
public async Task<string> HandleAsync(int millisecondsTimeout)
Create the task list and populate it with the workload.
Note that adding them to the list is not what starts the tasks, its the
File.WriteAllTextAsync that would have been the trigger.
var tasks = new List<Task<string>>();
Then wait for the tasks to all complete
This was adapted from stackoverflow.com examples and is very simliar to the list example above however the tasks are started using
var listOfSomething = new PopulateListOfSomething();