Use thread safe queues in MtObservableCollectionBase
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@@ -123,10 +124,10 @@ namespace Torch.Collections
|
|||||||
private readonly Timer _flushEventQueue;
|
private readonly Timer _flushEventQueue;
|
||||||
private const int _eventRaiseDelay = 50;
|
private const int _eventRaiseDelay = 50;
|
||||||
|
|
||||||
private readonly Queue<NotifyCollectionChangedEventArgs> _collectionEventQueue =
|
private readonly ConcurrentQueue<NotifyCollectionChangedEventArgs> _collectionEventQueue =
|
||||||
new Queue<NotifyCollectionChangedEventArgs>();
|
new ConcurrentQueue<NotifyCollectionChangedEventArgs>();
|
||||||
|
|
||||||
private readonly Queue<string> _propertyEventQueue = new Queue<string>();
|
private readonly ConcurrentQueue<string> _propertyEventQueue = new ConcurrentQueue<string>();
|
||||||
|
|
||||||
private void FlushEventQueue(object data)
|
private void FlushEventQueue(object data)
|
||||||
{
|
{
|
||||||
@@ -137,7 +138,8 @@ namespace Torch.Collections
|
|||||||
// :/, but works better
|
// :/, but works better
|
||||||
bool reset = _collectionEventQueue.Count > 0;
|
bool reset = _collectionEventQueue.Count > 0;
|
||||||
if (reset)
|
if (reset)
|
||||||
_collectionEventQueue.Clear();
|
while (_collectionEventQueue.Count > 0)
|
||||||
|
_collectionEventQueue.TryDequeue(out _);
|
||||||
else
|
else
|
||||||
while (_collectionEventQueue.TryDequeue(out NotifyCollectionChangedEventArgs e))
|
while (_collectionEventQueue.TryDequeue(out NotifyCollectionChangedEventArgs e))
|
||||||
_collectionChangedEvent.Raise(this, e);
|
_collectionChangedEvent.Raise(this, e);
|
||||||
|
Reference in New Issue
Block a user