[英]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命名空间中的相应类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.