Are linq operations on concurrent collections thread safe?

后端 未结 3 1658
忘掉有多难
忘掉有多难 2021-01-17 23:28

For example is the following code thread safe:

ConcurrentQueue _queue = new ConcurrentQueue();
while(true)
{
for(int y = 0; y < 3;         


        
3条回答
  •  走了就别回头了
    2021-01-17 23:48

    Yes, according to documentation

    The System.Collections.Concurrent namespace provides several thread-safe collection classes that should be used in place of the corresponding types in the System.Collections and System.Collections.Generic namespaces whenever multiple threads are accessing the collection concurrently.

提交回复
热议问题