12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 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<T> : BindingList<T>
- {
- 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);
- }
- }
- }
|