public void Add(ConcurrentIObservableVirtualizingObservableCollection <TestObject> collection) { for (var i = 0; i < Iterations; i++) { collection.Add(_data[i]); } }
public void AsyncVirtualizingObservableCollection() { var collection = new ConcurrentIObservableVirtualizingObservableCollection <TestObject>(); collection.CollectionChanged += this.collection_CollectionChanged; //collection.PropertyChanged += collection_PropertyChanged; this._testStopwatch.Start("AsyncVirtualizingObservableCollection iterative add with notifications"); for (var i = 0; i < Iterations; i++) { collection.Add(_data[i]); } this._testStopwatch.Stop(); this.CheckDataConsistency(collection); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection iterative add without notifications"); collection.SuspendCollectionChangeNotification(); for (var i = 0; i < Iterations; i++) { collection.Add(_data[i]); } collection.ResumeCollectionChangeNotification(); this._testStopwatch.Stop(); this.CheckDataConsistency(collection); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection bulk add"); collection.AddRange(_data); this._testStopwatch.Stop(); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection parallel add with notifications"); Parallel.ForEach(_data, item => { collection.Add(item); }); this._testStopwatch.Stop(); this.CheckDataConsistency(collection); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection parallel add without notifications"); collection.SuspendCollectionChangeNotification(); Parallel.ForEach(_data, item => { collection.Add(item); }); collection.ResumeCollectionChangeNotification(); this._testStopwatch.Stop(); this.CheckDataConsistency(collection); collection.Clear(); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection parallel add int without interlocked"); Parallel.ForEach(_data, item => { collection.Add(item); }); this._testStopwatch.Stop(); this.CheckDataConsistency(collection); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection Iterative add with parallel read"); Parallel.Invoke(() => this.Add(collection), () => this.Iteration(collection)); this.CheckDataConsistency(collection); this._testStopwatch.Stop(); this.CheckDataConsistency(collection); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection Iterative add with parallel read and remove"); var task = Task.Factory.StartNew(() => this.RemoveRandom(collection)); Parallel.Invoke(() => this.Add(collection), () => this.Iteration(collection)); this._testStopwatch.Stop(); this.IsRandomCanceled = true; task.Wait(); this.CheckDataConsistency(collection); this.RemovedObjects.Clear(); collection.Clear(); this._testStopwatch.Start("AsyncVirtualizingObservableCollection Iterative add with parallel long read and remove"); task = Task.Factory.StartNew(() => this.RemoveRandom(collection)); Parallel.Invoke(() => this.Add(collection), () => this.IterationLong(collection)); this._testStopwatch.Stop(); this.IsRandomCanceled = true; task.Wait(); this.CheckDataConsistency(collection); this.RemovedObjects.Clear(); collection.Clear(); }