I was trying to read in values from the GUI and I passed the data as shown below using Task. What I don’t understand is it gives error because of only combobox field (that is tab3_ddl_Range.SelectedText) and if I remove it the error goes away. Shouldn’t it still give the error? As I am accessing GUI from non GUI thread?
factoryA.StartNew(() => ReadInstrument_3(
Globls.numReadings, tab3_txt_Address.Text.TrimEnd(), tab3_rb_DCI.Checked,
tab2_rb_DCV.Checked, tab3_ddl_Range.SelectedText.TrimEnd(),
tab3_rb_FixedZ_10G.Checked, tab3_rb_FixedZ_10M.Checked,
tab3_rb_Azero_Off.Checked, tab3_rb_Azero_On.Checked,
tab3_rb_Azero_Once.Checked, tab3_txt_Aper.Text.TrimEnd(),
tab3_txt_Device_Timeout.Text.TrimEnd(), tab3_txt_SICL.Text.TrimEnd())
Some properties of controls are cached and don’t require a winapi call to retrieve their values. In particular the Text property is stored in an internal string. So reading the Text property in a thread doesn’t raise an exception since that just returns the string value. Writing however does, that requires updating that string and making a winapi call to update the native window.
It is the winapi call that triggers the exception. In particular, accessing the Handle property.