reading a checkbox from another thread
-
I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:
-
I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:
I didn't try it, but Invoke should do the trick to read a check box state.
-
I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:
Why use Invoke? Just read the control like usual..
private void btnReadControlThread\_Click(object sender, EventArgs e) { Thread thread = new Thread(ThreadReadControl); thread.Start(); } private void ThreadReadControl() { // read fr control is allowed MessageBox.Show("Enable status is " + cbEnableStatus.Checked.ToString()); // below write to control is not allow, use Invoke // cbEnableStatus.Checked = true; }
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
} -
Why use Invoke? Just read the control like usual..
private void btnReadControlThread\_Click(object sender, EventArgs e) { Thread thread = new Thread(ThreadReadControl); thread.Start(); } private void ThreadReadControl() { // read fr control is allowed MessageBox.Show("Enable status is " + cbEnableStatus.Checked.ToString()); // below write to control is not allow, use Invoke // cbEnableStatus.Checked = true; }
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
}Many thanks. Typical! me trying to overcomplicate things again. Cheers Bruce:thumbsup:
-
I have spent some hours trying to read a checkbox enabled status on form1 from a different thread without any joy. Lots of research about Invoke etc has shown me how to write to the form but no clue as to how to read from the form. Can anyone here point me in the right direction please? Cheers, Bruce :confused:
Not sure about the safety of reading properties directly across threads as opposed to calling methods etc... I suppose you could provide a GetEnabled (and if needed SetEnabled) method that use the property's getter (and setter) and call Invoke on that.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)