Пример #1
0
 public void Add(ConcurrentIObservableVirtualizingObservableCollection <TestObject> collection)
 {
     for (var i = 0; i < Iterations; i++)
     {
         collection.Add(_data[i]);
     }
 }
Пример #2
0
        public void IterationLong(ConcurrentIObservableVirtualizingObservableCollection <TestObject> collection)
        {
            var j = 0;

            foreach (var item in collection)
            {
                j++;
                if (j > 1000)
                {
                    break;
                }
            }
        }
Пример #3
0
 private void RemoveRandom(ConcurrentIObservableVirtualizingObservableCollection <TestObject> collection)
 {
     while (!this.IsRandomCanceled)
     {
         Thread.Sleep(10);
         try
         {
             var removed = collection[1];
             this.RemovedObjects.Add(removed);
             collection.Remove(removed);
         }
         catch (ArgumentOutOfRangeException) { }
     }
 }
Пример #4
0
        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();
        }