I have a class with the following method:
public List bikesCopy
{
get
{
List bs;
lock (_bikes) bs = new Li
This error occurs because multiple threads are adding items in a single list. Lists are by default not a thread-safe solution. In a multi-threaded code, it is only recommended to read from a list, and not write to it.
As described here:
If you are only reading from a shared collection, then you can use the classes in the System.Collections.Generic namespace.
Better use a thread-safe solution like System.Collections.Concurrent namespace which provides implementations like ConcurrentBag, ConcurrentDictionary, ConcurrentQueue, ConcurrentStack etc.
For example:
public ConcurrentBag bikesCopy
{
get => new ConcurrentBag()
}