Get Checked value of a checkBox from thread different of the UI thread
-
Well i know that i can´t play directly with values of winforms from different thread of the UI thread. But i have a thread and i need to obtain the value of a checkbox from that thread... how can i obtain the value?? Thanks in advance. :)
-
Well i know that i can´t play directly with values of winforms from different thread of the UI thread. But i have a thread and i need to obtain the value of a checkbox from that thread... how can i obtain the value?? Thanks in advance. :)
Hi, for minimal run-time cost, give the Form that holds the CheckBox: 1. a private bool holding the state of the checkbox; 2. a CheckBox_CheckedChanged event handler, updating said variable; 3. a public property to get the value of said variable. this set-up avoids the need for Control.Invoke PS: don't forget to copy the initial CheckBox.Checked value in your form's constructor. :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
Well i know that i can´t play directly with values of winforms from different thread of the UI thread. But i have a thread and i need to obtain the value of a checkbox from that thread... how can i obtain the value?? Thanks in advance. :)
I have an other Thread t,and I can get the checkbox value from UI thread in Thread t. see follow source code.
private void Form2\_Load(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(deal)); t.Name = "deal"; t.IsBackground = true; t.Start(); } void deal() { while (true) { System.Diagnostics.Debug.WriteLine(checkBox1.Checked); Thread.Sleep(1000); } }