Hi, just run this Console application code and compare the results using foreach and Parallel.Foreach. In principle, Parallel is useful in tasks with a long lead time or in tasks that consume too much time.
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List<object> objectList = new List<object>(); var listItem = new List<Person> { new Person { Id = 1, Name = "Person 1" }, new Person { Id = 2, Name = "Person 2" }, new Person { Id = 3, Name = "Person 3" } , new Person { Id = 4, Name = "Person 4" } }; var start = DateTime.Now; var parallelList = listItem;
Output

source share