T
Trecius
Hello, Newsgroupians:
I have a question regarding threads changing the UI of a form. I have an
external device that sends signals to my application by using their library.
To do this, all I need to do is set the event that handles the incoming data.
public class Reader
{
private WeightReader m_reader;
...
public Reader()
{
this.m_reader.ResponseEvent += new
WeightReader.Response(this.ReceiveData);
}
public void ReceiveData(WeightEventArgs args)
{
...
}
}
Because ReceiveData is being called from an external thread, I do the
following before my program is initialized...
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
To make a long story short, in my ReceiveData(), I check the arguments that
come in and change my UI accordingly. I can set the text of a control
without any problem; however, if at any time a control needs to have its
Visible property set, the program just hangs. How can I get around this?
Here's a sample application that I have written; it only has a button and a
textbox. Initially, the textbox's Visible property is set to false when
intialized. Overall, this small application indicates the problem I am
having that an external thread cannot set the Visible property of a control;
however, it has the ability to set the text of a control. Why's this?
public partial class TempFrm : Form
{
public TempFrm()
{
InitializeComponent();
this.button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread th = new System.Threading.Thread(new
System.Threading.ThreadStart(this.Temp));
th.Start();
}
void Temp()
{
this.textBox1.Visible = true; // This does not work
//this.textBox1.Text = "Hello"; // This works if textBox1 is INITIALLY
visible
}
}
Thank you, all.
Trecius
I have a question regarding threads changing the UI of a form. I have an
external device that sends signals to my application by using their library.
To do this, all I need to do is set the event that handles the incoming data.
public class Reader
{
private WeightReader m_reader;
...
public Reader()
{
this.m_reader.ResponseEvent += new
WeightReader.Response(this.ReceiveData);
}
public void ReceiveData(WeightEventArgs args)
{
...
}
}
Because ReceiveData is being called from an external thread, I do the
following before my program is initialized...
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
To make a long story short, in my ReceiveData(), I check the arguments that
come in and change my UI accordingly. I can set the text of a control
without any problem; however, if at any time a control needs to have its
Visible property set, the program just hangs. How can I get around this?
Here's a sample application that I have written; it only has a button and a
textbox. Initially, the textbox's Visible property is set to false when
intialized. Overall, this small application indicates the problem I am
having that an external thread cannot set the Visible property of a control;
however, it has the ability to set the text of a control. Why's this?
public partial class TempFrm : Form
{
public TempFrm()
{
InitializeComponent();
this.button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread th = new System.Threading.Thread(new
System.Threading.ThreadStart(this.Temp));
th.Start();
}
void Temp()
{
this.textBox1.Visible = true; // This does not work
//this.textBox1.Text = "Hello"; // This works if textBox1 is INITIALLY
visible
}
}
Thank you, all.
Trecius