In C # We often use a variety of collections, arrays, list,dictionary,stack, and so on, but these collections are non-thread-safe, when multithreading at the same time read and write these collections, it is possible to cause the data inside the confusion, For this reason, Microsoft has specifically provided another set of thread-safe versions (placed in the System.Collections.Concurrent namespace) from Net4.0.
There are all these:
When multiple threads concurrently access the collection, these classes should be used in place of the corresponding types in the System.Collections and System.Collections.Generic namespaces.
|
class |
description |
|
Blockingcollection<t> |
Provides blocking and throttling capabilities for implementing a thread-safe collection of iproducerconsumercollection<t>. |
|
Concurrentbag<t> |
Represents an unordered collection of thread-safe objects. |
|
Concurrentdictionary<tkey, tvalue> |
Represents a thread-safe collection of key-value pairs that can be accessed concurrently by multiple threads. |
|
Concurrentqueue<t> |
Represents a thread-safe FIFO (FIFO) collection. |
|
Concurrentstack<t> |
Represents a thread-safe last-in-first-out (LIFO) collection. |
|
Orderablepartitioner<tsource> |
Represents a specific way to split a sortable data source into multiple partitions. |
|
Partitioner |
Provides common partitioning policies for arrays, lists, and enumerable items. |
|
Partitioner<tsource> |
Represents a specific way to split a data source into multiple partitions. |
|
Interface |
description |
|
Iproducerconsumercollection<t> |
Defines a method that is used by the manufacturer/consumer to manipulate the thread-safe collection. This interface provides a uniform representation (for producer/consumer collections), thus higher level abstractions such as system.collections.concurrent.blockingcollection<t> can use the collection as the underlying storage mechanism. |
Thread-safe versions of various common collection types in C #