Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is SynchronizedCollection<T> in the System.ServiceModel assembly?

Tags:

.net

I was wondering if anybody has any idea why the SynchronizedCollection<T> class was implemented in the ServiceModel assembly. I cannot see any connection between the assembly name and this (relatively) general purpose class.

like image 319
cvlad Avatar asked Jun 11 '11 10:06

cvlad


1 Answers

This class is quite specific, and its name could even be misleading - its internal implementation does virtually nothing except for wrapping some operations (Insert, Add, Clear, IndexOf etc.) in lock (this.sync) {} block, which doesn't make it actually Synchronized (see concerns described in this article - in short, compound operations like LINQ FirstOrDefault are not thread-safe on SynchronizedCollection, as they do not acquire the lock).

It is heavily used in ServiceModel assembly itself, and probably was made public only because some ServiceModel classes expose public properties of this type.

So my guess is: it was put into ServiceModel assembly because it doesn't really belong to BCL and is just a DRYish BCL namespace extension for internal ServiceModel needs.

like image 102
lxa Avatar answered Nov 15 '22 09:11

lxa