I have potentially several thousand independent tasks that need to be run. Each of them may make database calls, so they're already leveraging async where possible. That said, if I wanted all of them to run in parallel what's the best way to do this?
I've got this currently:
Parallel.For(0, items.Count, async _ => await PerformTask());
I've also considered using:
List<Task> tasks = new List<Task>();
for(var i = 0; i < items.Count; ++i) tasks.Add(PerformTask());
await Task.WhenAll(tasks); // or possibly Task.WaitAll(tasks.ToArray())
Is there an objectively best way to do this?
Edit: This is different from the marked duplicate question since I'm not asking the difference. I'm asking which way is correct for my use case.