I have a background worker which needs to grab comboBox1.SelectedItem, however it’s on a different thread and thus I’m unable to “reach” the GUI (as the GUI is on the main thread).
How would I do this?
I’ve tried using a delegate however this doesn’t seem to work.
private delegate string ReadComboDelegate(ComboBox c);
private string ReadComboBox(ComboBox c)
{
if(c.InvokeRequired)
{
ReadComboDelegate del = new ReadComboDelegate(this.ReadComboBox);
return (string) c.Invoke(del,c);
}
else
{
return c.Text;
}
}
Ideally, you should pass the SelectedItem (and any other data you might require) to the method representing the background worker.
If thats not possible, then you can use comboBox1.Invoke method to communicate with the UI thread.