Monday, 9 July 2012

Using Parallel.ForEach in .NET

Just watching a Pluralsight video about VB.NET and the CLR and I came across the System.Threading.Tasks namespaces Parallel static class. 

It seems a nice tidy way of multi threading when iterating over things. I think I have been missing a trick! :-) 

https://gist.github.com/3077469

Essentially you just pass the collection as the first parameter and a delegate as the next. See the example or just Google it. 

You can also whip the .AsParallel(); extension method on the end of your Linq queries for similar parallel joy. 

It's possible I knew about this before but the rediscovery is very pleasing indeed. 

 

 

No comments:

Comments System

Disqus Shortname