Why doesn’t ConcurrentBag implement ICollection<T>?

May 4, 2011

Hopefully you’ve encountered by now the System.Collections.Concurrent namespace. It’s new to .NET 4, and it has many useful data structures which are optimized for multi-threaded usage. ConcurrentBag, for instance, is an unordered collection of objects, which multiple threads can add and remove objects from at the same time. Recently I needed to test that some piece of code was thread-safe. To do that, I wanted to run it once synchronously, and once asynchronously. It looked something like that: 1: private static IEnumerable<ComputationResult> ComputeSynchronous(IEnumerable<string> inputs) ...
no comments