Thread-Safe collections in C#

CsharpProgrammingServer Side Programming

The .NET Framework 4 introduced System.Collections.Concurrent namespace. The namespace has numerous collection classes. These classes are both thread-safe and scalable. Multiple threads can safely add or remove items from these collections,

The following concurrent collection types use lightweight synchronization mechanisms: SpinLock, SpinWait, etc. These are new in .NET Framework 4.

Let us see the concurrent collection in C# −

Sr.No. Type & Description
1

BlockingCollection<T>

Bounding and blocking functionality for any type.

2

ConcurrentDictionary<TKey,TValue>

Thread-safe implementation of a dictionary of key-value pairs.

3

ConcurrentQueue<T>

Thread-safe implementation of a FIFO (first-in, first-out) queue.

4

ConcurrentStack<T>

Thread-safe implementation of a LIFO (last-in, first-out) stack.

5

ConcurrentBag<T>

Thread-safe implementation of an unordered collection of elements.

6

IProducerConsumerCollection<T>

The interface that a type must implement to be used in a BlockingCollection

raja
Published on 21-Aug-2018 12:54:45
Advertisements