You cannot access GUI elements in a thread other than a GUI. You will need to determine if a call to the GUI thread is required. For example (here I made some of them earlier):
public delegate void SetEnabledStateCallBack(Control control, bool enabled); public static void SetEnabledState(Control control, bool enabled) { if (control.InvokeRequired) { SetEnabledStateCallBack d = new SetEnabledStateCallBack(SetEnabledState); control.Invoke(d, new object[] { control, enabled }); } else { control.Enabled = enabled; } }
or
public delegate void AddListViewItemCallBack(ListView control, ListViewItem item); public static void AddListViewItem(ListView control, ListViewItem item) { if (control.InvokeRequired) { AddListViewItemCallBack d = new AddListViewItemCallBack(AddListViewItem); control.Invoke(d, new object[] { control, item }); } else { control.Items.Add(item); } }
Then you can set the enabled property (from my first example) with ClassName.SetEnabledState(this, true); .
GenericTypeTea Jun 14 2018-10-12T00: 00Z
source share