When observe the definition of
ICollection extends IEnumerable. It provides size and synchronization members in addition to enumeration.
Does synchronization here represent the synchronization of collection ,when it is shared
by multiple threads?.Kindly explain me with simple example how can i practically use “ICollection.IsSynchronized Property“.
Thanks.
If
IsSynchronizedis true, the collection should be thread-safe. However, you still may have to use a lock around multiple list operations (such as finding and index before inserting or whatever) and in this case you can use theSyncRootproperty.Note, however, that both members are only present in the non-generic
ICollectioninterface. The newer (.NET 2)ICollection<T>interface doesn’t offer them, and frankly, usually you’re going to lock yourself instead of using a synchronized list.