Parallel.ForEach behavior

Monday, February 27, 2012

Parallel.ForEach behavior this post is a direct continuation for the previous post about "Real-life story: Blocking Collection". (Real-life story: Blocking Collection).ContinueWith (t => this post); or await (Real-life story: Blocking Collection); this post; my colleague Bram Veldhoen has suggest to demonstrate the behavior of the Parallel.ForEach thread's hunger in more pure fashion which doesn't include BlockingCollection<T> or any other high level Enumerable. the following code demonstrate the issue by using a slow Enumerable: Code...

Real-life story: Blocking Collection

Sunday, February 26, 2012

Real-life story: Blocking Collection this post will discuss a real-life story which uncover none trivial (yet logical) behavior which related to Parallel.ForEach and BlockingCollection<T>. I will explain why it happens and what how can we handle it right. it all start when Guy Eden from ITG has found that the following code seem to leak memory: Code Snippet private static void Main() {     var bc = new BlockingCollection<int>();     Task.Factory.StartNew(() =>         Parallel.ForEach(bc.GetConsumingEnumerable(), i => { }));     Console.ReadKey(); } it was leaking even those the...