我想知道是否有人知道为什么 SynchronizedCollection
最佳答案
这个类非常具体,它的名字甚至可能会产生误导——它的内部实现几乎什么都不做,除了在 Insert
中包装一些操作(Add
、Clear
、IndexOf
、lock (this.sync) {}
等)。 block ,这并没有使它真正同步(参见 this article 中描述的问题 - 简而言之,像 LINQ FirstOrDefault
这样的复合操作在 SynchronizedCollection
上不是线程安全的,因为它们不获取锁)。
它在 ServiceModel
中大量使用组装本身,可能是由 public
只是因为一些ServiceModel
类公开这种类型的公共(public)属性。
所以我的猜测是:它被放入 ServiceModel
程序集,因为它实际上并不属于 BCL,而只是内部 ServiceModel
的 DRYish BCL 命名空间扩展需要。
关于.net - 为什么 SynchronizedCollection<T> 在 System.ServiceModel 程序集中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6315406/