Parallel.ForEach vs Task.Factory.StartNew

What is the difference between the below code snippets? Won’t both be using threadpool threads?

For instance if I want to call a function for each item in a collection,

Parallel.ForEach<Item>(items, item => DoSomething(item));

vs

foreach(var item in items)
{
  Task.Factory.StartNew(() => DoSomething(item));
}

4 Answers
4

Leave a Comment