private void UpdateSnapshot() { if (_newSnapshotRequired) { _snapshotLock.TryEnterWriteLock(Timeout.Infinite); if (_newSnapshotRequired) { _baseSnapshot = new ImmutableCollectionImpl <T>(WriteCollection); _newSnapshotRequired = false; } _snapshotLock.ExitWriteLock(); } }
protected ConcurrentCollection(IEnumerable <T> Items) { _subscribers = new Dictionary <int, IObserver <NotifyCollectionChangedEventArgs> >(); WriteCollection = new ObservableCollection <T>(Items); _baseSnapshot = new ImmutableCollectionImpl <T>(Items); ViewModel = new ConcurrentCollectionViewModel <T>(this); WriteCollection.CollectionChanged += HandleBaseCollectionChanged; ViewModel.CollectionChanged += (sender, e) => CollectionChanged?.Invoke(sender, e); }