standards-c-sharp
standards-c-sharp copied to clipboard
Don't use SynchronizedCollection<T> , Use collections provided by the System.Collections.Concurrent
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
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.