System.Collections.Concurrent

Efficient, thread-safe operations for access collection items from multiple threads. Concurrent collection classes do not require user code to take any locks when accessing items.

  • BlockingCollection<T> — provides blocking & bounding capabilities;
    • Producer threads block if not slots are available or if collection is full.
    • Consumer threads block if collection is empty.
    • Class can be used as backing store to provide blocking & bounding for any collection that implements IEnumerable<T>.
  • ConcurrentBag<T> — Use for scalable add/get operations.
  • ConcurrentDictionary<Tkey, Tvalue>
  • ConcurrentQueue<T> — FIFO
  • ConcurrentStack<T> — LIFO