Parallel.ForEach and the Task Parallel Library
The Task Parallel Library or TPL is a collection of classes designed to make multi-threading and parallel coding a lot easier and safer now that we have multi-core processors widely available.
One of the feature in the TPL is the Parallel.ForEach which will let you parallelize your loop if order of execution is not important. It will let you parallelize your work in no time without the need of starting up and handling threads on your own.
public void ParallelForEach()
{
var testList = new List<string> { "One", "Two", "Three", "Four", "Five" };
System.Threading.Tasks.Parallel.ForEach(testList, item => Console.WriteLine(item));
}
The Task Parallel Library or TPL is a collection of classes designed to make multi-threading and parallel coding a lot easier and safer now that we have multi-core processors widely available.
One of the feature in the TPL is the Parallel.ForEach which will let you parallelize your loop if order of execution is not important. It will let you parallelize your work in no time without the need of starting up and handling threads on your own.
public void ParallelForEach()
{
var testList = new List<string> { "One", "Two", "Three", "Four", "Five" };
System.Threading.Tasks.Parallel.ForEach(testList, item => Console.WriteLine(item));
}