---
title: "How Parallel.ForEach works internally?"  
description: "How Parallel.ForEach works internally?"  
author: "Anupam Mishra"  
published: 2016-01-13  
updated: 2016-01-14  
canonical: https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally  
category: "c#"  
tags: ["c#", ".net", "threading"]  
reading_time: 2 minutes  

---

# How Parallel.ForEach works internally?

i just like to know how Parallel.ForEach() works?does it start [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) thread or it is not at all related with thread?thank you.\

## Replies

### Reply by Manoj Bhatt

The Parallel class’s **ForEach** method is a multi-threaded implementation of a common loop construct in C#, the **foreach** loop. Recall that a foreach loop allows you to iterate over an enumerable data set represented using an **IEnumerable**.

**Parallel.ForEach** is similar to a **foreach** loop in that it iterates over an enumerable data set, but unlike **foreach**, **Parallel.ForEach** uses multiple threads to evaluate different invocations of the loop body. As it turns out, these characteristics make **Parallel.ForEach** a broadly useful mechanism for data-parallel programming. In order to evaluate a function over a sequence in parallel, an important thing to consider is how to break the iteration space into smaller pieces that can be processed in parallel. This partitioning allows each thread to evaluate the loop body over one partition.

**Parallel.ForEach** has numerous overloads.The IEnumerable source specifies the sequence to iterate over, and the Action body specifies the delegate to invoke for each element. For the sake of simplicity, we won’t explain the details of the other signatures of Parallel.ForEach; the list of different overloads can be found [here.](https://msdn.microsoft.com/en-us/library/dd321840(VS.100).aspx)


---

Original Source: https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
