Possible Duplicate:
Cross-thread operation not valid
My function I put to new thread, but it doesn't work. I have exception:
Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.
My code:
void licz()
{
int wynik = 0;
for (int i = 0; i < 200; i++)
{
wynik =+ i;
textBox1.Text += wynik.ToString() + Environment.NewLine;
}
MessageBox.Show("Wynik: " + wynik);
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread th1 = new Thread(licz);
th1.Start();
}
How fix it?