Thursday, February 9, 2017

C# snippet on easy multi-threading / parallel processing

There's been a need of mine lately to figure out how to successfully execute parallel programming tasks in C#. Finally figured out a basic way to do this, that uses current versions of .NET. The Threading in C# website was key to this.

using System.Threading.Tasks;
// The "i" is an iterator you can refer to in the body
Parallel.ForEach(array, (c, state, i) => {
On an unrelated note: if you have to parse XML for some reason, XElement seems to be much easier to use than the older libraries.

Added: someone else wrote a good comparison of different threading methods in .NET.

No comments:

Post a Comment