The last class we will touch on in this TPL primer is the
Parallel class. This class will be covered in detail in Chapter 7, Data Parallelism, when we discuss data parallelism; but it is worth an introduction here. The
Parallel class is part of the
System.Threading.Tasks namespace and provides functionality for using parallel loops. The two most used methods are
Parallel.ForEach, which allow you to loop through a collection and perform logic on each item of the collection concurrently.
We briefly saw it earlier in this chapter when we used the
Parallel.Invoke method to run a group of tasks in parallel. But its main use is for data parallelism.
We can call the
Parallel.For method using a named method, ...