/// <summary> /// In this class modifying the list is thread safe. To enumerate through the list, always lock the SyncRoot property, otherwise it will not be thread safe. This is the recommended way of making a collection thread safe. /// </summary> /// <typeparam name="T">The type of the entity for which the collection is created.</typeparam> [Serializable] [DataContract] public class WriteThreadSafeCollection<T> : Collection<T> { private object _syncLock = new object(); public WriteThreadSafeCollection() : base() { } public WriteSynchronizedCollection(IList<T> sourceList) : base() { this.AddRange(sourceList); } protected override void InsertItem(int index, T item) { lock (_syncLock) { base.InsertItem(index, item); } }