Note: this is a C# 4.0 feature
The first loop run in a serial matter, and the second one parallel. First one is guaranteed output ABCD, but the second write these characters in a random fashion
The first loop run in a serial matter, and the second one parallel. First one is guaranteed output ABCD, but the second write these characters in a random fashion
List<string> strCollection = new List<string>() { "A", "B", "C", "D" }; // Process one at a time foreach (string str in strCollection) { Console.WriteLine(str); } // Process in parallel System.Threading.Tasks.Parallel.ForEach(strCollection, str => { Console.WriteLine(str); });
No comments:
Post a Comment