List<Employee> employeeList = new List<Employee>();
List<Event> eventList = new List<Event>();
//Wanted to execute each foreach call asynchronously, to improve performance
foreach (var account in accounts)
{
var context = await GetContext(account);
//following two await is depends on above result
var employees = await _employeeService.List(context);
var events = await _eventService.List(context).ConfigureAwait(false);
//Question is how to execute above two await calls parallely
employeeList.AddRange(employees);
eventList.AddRange(events);
}
I want to fire off two long-running tasks(employees and Events) at the same time. So maybe can we achieve parallel execution for each account above to solve this?