Here is my scenarion:
I have a GridControl bound to a BindingList. At first what I was doing was creating a worker thread and access the BindingList directly, but th
I subclassed BindingList so I could check for a required Invoke. This way my business objects do not have a reference to the UI.
public class InvokingBindingList : BindingList
{
public InvokingBindingList(IList list, Control control = null) : base(list)
{
this.Control = control;
}
public InvokingBindingList(Control control = null)
{
this.Control = control;
}
public Control Control { get; set; }
protected override void OnListChanged(ListChangedEventArgs e)
{
if (Control?.InvokeRequired == true)
Control.Invoke(new Action(() => base.OnListChanged(e)));
else
base.OnListChanged(e);
}
}