using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ips.Library.Basic { public class ThreadedBindingList : BindingList { public ThreadedBindingList() { _ctx = SynchronizationContext.Current; } public SynchronizationContext SynchronizationContext { get { return _ctx; } set { _ctx = value; } } SynchronizationContext _ctx; protected override void OnAddingNew(AddingNewEventArgs e) { if (_ctx == null) { BaseAddingNew(e); } else { SynchronizationContext.Current.Send(delegate { BaseAddingNew(e); }, null); } } void BaseAddingNew(AddingNewEventArgs e) { base.OnAddingNew(e); } protected override void OnListChanged(ListChangedEventArgs e) { if (_ctx == null) { BaseListChanged(e); } else { _ctx.Send(delegate { BaseListChanged(e); }, null); } } void BaseListChanged(ListChangedEventArgs e) { base.OnListChanged(e); } } }