Is it safe to use the following pattern in a multithreaded scenario?:
var collection = new List<T>(sharedCollection);
Where sharedCollection
can be modified at the same time by another thread (i.e. have elements added or removed from it)?
The scenario I'm currently dealing with is copying the items from a BindingList
, but the question should be relative to any standard collection type.
If it isn't thread safe, should I put a lock on the sharedCollection
, or are there better solutions?