private void button1_Click(object sender, EventArgs e)
{
t = new Thread(new ParameterizedThreadStart(startRequest));
t.Start(textBox1);
}
void startRequest(object textBox1)
{
textBox1.Text = "hello";
}
here I get an error that textBox1 doesn’t have a property Text, in the main thread its all okay, but in the new thread I get an error ,how to fix this?
You must cast your
objectto TypeTextBoxbefore using its Text property.Its also better to check for null, if the casting fails.