aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core/SynchronizedObservableCollection.cs
blob: f0a13b3c960311044cfdc5b3307fec0dec6f0f53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace Tango.Core
{
    public class SynchronizedObservableCollection<T> : ObservableCollection<T>
    {
        public SynchronizedObservableCollection() : base()
        {
            this.EnableCrossThreadOperations();
        }

        public SynchronizedObservableCollection(IEnumerable<T> collection) : base(collection)
        {

        }

        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            if (ObservableEntityCollectionSettings._dispatcher != null)
            {
                ObservableEntityCollectionSettings._dispatcher.BeginInvoke(new Action(() =>
                {
                    base.OnCollectionChanged(e);
                }));
            }
            else
            {
                base.OnCollectionChanged(e);
            }
        }
    }
}