Reputation: 4303
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.
Upvotes: 1
Views: 260
Reputation: 60256
If IsSynchronized
is 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 the SyncRoot
property.
Note, however, that both members are only present in the non-generic ICollection
interface. 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.
Upvotes: 1