Skip to Content
Introducing .NET 4.0: with Visual Studio 2010
book

Introducing .NET 4.0: with Visual Studio 2010

by Alex Mackey
February 2010
Beginner content levelBeginner
400 pages
11h 13m
English
Apress
Content preview from Introducing .NET 4.0: with Visual Studio 2010

5.3. Parallel Loops

One of the easiest ways to parallelize your application is by using the parallel loop construct. Two types of loops can be run in parallel:

  • Parallel.For()

  • Parallel.ForEach()

Let's take a look at these now.

5.3.1. Parallel.For()

In our example application, we will stick with the stock quote scenario described previously, create a list of stock quotes, and then iterate through them using a Parallel.For() loop construct, passing each quote into a function that will simulate a long-running process.

To see the differences between running code in serial and parallel, we will also perform this task using a standard for loop. We will use a stopwatch instance to measure the time each loop takes to complete. It is worth stressing that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 3.5 For Dummies®

ASP.NET 3.5 For Dummies®

Ken Cox
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9781430224556Purchase book