Parallelisation Talk Example – ConcurrentBag

This example shows a ConcurrentBag being populated and it being accessed while another task is still populating the bag. The ConcurrentBag class can be found in the System.Collections.Concurrent namespace In this example, the ConcurrentBag is populated in task that is running in the background. After a brief pause in order to allow the background task […]

Parallelisation Talk Examples – ConcurrentDictionary

The example used in the talk was one I had already blogged about. The original blog entry the example was based upon is here: Parallelisation in .NET 4.0 – The ConcurrentDictionary. Code Example class Program { private static ConcurrentDictionary<string, int> wordCounts = new ConcurrentDictionary<string, int>(); static void Main(string[] args) { string[] lines = File.ReadAllLines("grimms-fairy-tales.txt"); Parallel.ForEach(lines, […]

Parallelisation Talk Examples – Basic PLINQ

These are some code examples from my introductory talk on Parallelisation showing the difference between a standard sequential LINQ query and its parallel equivalent. The main differences between this and the previous two examples (Parallel.For and Parallel.ForEach) is that LINQ (and PLINQ) is designed to return data back, so the LINQ expression uses a Func<TResult, […]

Parallelisation Talk Examples – Parallel.ForEach

These are some code examples from my introductory talk on Parallelisation. Showing the difference between a standard sequential foreach loop and its parallel equivalent. Code example 1: Serial processing of a foreach loop class Program { private static Random rnd = new Random(); static void Main(string[] args) { DateTime start = DateTime.UtcNow; IEnumerable items = […]

Parallelisation Talk examples – Parallel.For

This is some example code from my introductory talk on Parallelisation. Showing the difference between a standard sequential for loop and its parallel equivalent. Code example 1: Serial processing of a for loop class Program { private static Random rnd = new Random(); static void Main(string[] args) { DateTime start = DateTime.UtcNow; for (int i […]