O'Reilly logo

C# Multithreaded and Parallel Programming by Rodney Ringler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introducing the Parallel class

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.For and 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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required