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

use*_*951 6 .net generics collections multithreading thread-safety

我们如何知道方法是否是线程安全的

例如,如果我查看http://msdn.microsoft.com/en-us/library/3wcytfd1.aspx,则没有任何内容表明其线程安全性.

Mit*_*eat 10

不,它们不是线程安全的(没有执行自己的锁定).

请改为使用其中一个Concurrent集合.

线程安全的集合

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