In this chapter, we are going to cover the following recipes:
BlockingCollection
BlockingCollection
with GetConsumingEnumerable
ConcurrentStack
ConcurrentDictionary
ConcurrentStack
IProducerConsumerCollection
Although System.Collections
namespace offers a wide range of collections; the only thing which limits our use of them in a multi-threaded or parallel environment is that they are not thread safe. A non thread safe collection could lead to race conditions, which is a condition that occurs when two or more threads can access shared data and try to change it at the same time, producing unexpected errors.
Concurrent collections in .NET Framework 4.5 allow the developers to create type safe as well as thread safe collections. These collection classes form an essential part of the parallel programming feature and are available under the namespace
System.Collections.Concurrent
.
18.117.111.1