How to read combobox from a thread other than the thread it was created on?
You can do it like this:
this.Invoke((MethodInvoker)delegate() { text = combobox.Text; });
You can still use Invoke
and read it to a local variable.
Something like this:
string text;this.Invoke(new MethodInvoker(delegate() { text = combobox.Text; }));
Since Invoke
is synchronous you have the guarantee that text
variable will contain the value of the combo box text after it returns.
Shortest way is:
string text;this.Invoke(() => text = combobox.Text);