standards-c-sharp icon indicating copy to clipboard operation
standards-c-sharp copied to clipboard

Don't use SynchronizedCollection<T> , Use collections provided by the System.Collections.Concurrent

Open c2trl opened this issue 2 years ago • 1 comments

List<T> => SynchronizedCollection<T> SynchronizedCollection<T> : use lock statement in every access

You should use one of the collections provided by the System.Collections.Concurrent namespace When to Use a Thread-Safe Collection

c2trl avatar Mar 17 '22 05:03 c2trl

That is a very good point, we should revise the collection suggestions (ref: https://github.com/agoda-com/standards-c-sharp/blob/aad4949aca6c6e6bb5db9f59310d0094c55c0f60/docs/collections/choosing-collection-implementation.md). There might be several analogs for a List<T> based on use-case, but SynchronizedCollection is probably the worst choice due to the global lock on every operation, as @c2trl mentioned.

szaboopeeter avatar Mar 17 '22 10:03 szaboopeeter