简体   繁体   English

generic.list和generic.dictionary线程在.net中是否安全

[英]Are generic.list and generic.dictionary thread safe in .net

How do we know whether a method is thread safe or not 我们如何知道方法是否是线程安全的

For example, if I check http://msdn.microsoft.com/en-us/library/3wcytfd1.aspx there is nothing that indicates its thread-safety. 例如,如果我查看http://msdn.microsoft.com/en-us/library/3wcytfd1.aspx ,则没有任何内容表明其线程安全性。

No, they are not thread safe (without performing your own locking). 不,它们不是线程安全的(没有执行自己的锁定)。

Use one of the Concurrent collections instead. 请改为使用其中一个Concurrent集合。

Thread-Safe Collections 线程安全的集合

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. System.Collections.Concurrent命名空间提供了几个线程安全的集合类,只要多个线程同时访问集合,就应该使用它们来代替System.Collections和System.Collections.Generic命名空间中的相应类型。

The documentation for the entire List<T> class has a segment on thread safety: 整个List<T>类的文档有一个关于线程安全的段:

Public static (Shared in Visual Basic) members of this type are thread safe. 此类型的公共静态(在Visual Basic中为Shared)成员是线程安全的。 Any instance members are not guaranteed to be thread safe. 任何实例成员都不保证是线程安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM