Does Parallel.ForEach require AsParallel()

Posted by dkackman on Stack Overflow See other posts from Stack Overflow or by dkackman
Published on 2010-02-16T01:29:03Z Indexed on 2010/06/09 14:12 UTC
Read the original article Hit count: 365

ParallelEnumerable has a static member AsParallel. If I have an IEnumerable<T> and want to use Parallel.ForEach does that imply that I should always be using AsParallel?

e.g. Are both of these correct (everything else being equal)?

without AsParallel:

List<string> list = new List<string>();
Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)), f => list.Add(f));

or with AsParallel?

List<string> list = new List<string>();
Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)).AsParallel(), f => list.Add(f));

© Stack Overflow or respective owner

Related posts about .net-4.0

Related posts about PLINQ