Parallel.ForEach vs Task.Run and Task.WhenAll
What are the differences between using Parallel.ForEach or Task.Run() to start a set of tasks asynchronously? Version 1: List<string> strings = new List<string> { "s1", "s2", "s3" }; Parallel.ForEach(strings, s => { DoSomething(s); }); Version 2: List<string> strings = new List<string> { "s1", "s2", "s3" }; List<Task> Tasks = new List<Task>(); foreach (var s in strings) { Tasks.Add(Task.Run(() => DoSomething(s))); } await Task.WhenAll(Tasks); In this case, the second method will asynchronously wait for the tasks to complete instead of blocking. However, there is a disadvantage to use Task.Run