it's possible? I need for example,set new value to an label in thread execution.
I tried this:
private void button1_Click_1(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(DoWork));
th.Start();
}
public void DoWork()
{
while (true)
{
StartSearch(path, ref httpRequest);
}
}
public void StartSearch(string path, ref HttpWebRequest httpRequest) {
foo.GetTopic(path, delegate(string post, string name, string uid)
{
{
if (post.Contains("<font color=\"#0000FF\">"))
{
string msg = string.Format("Post:{0}\r\nby {1}({2})", post, name, uid);
//MessageBox.Show(msg);
labelX.text = msg;
}
}
}
);
}
I'm getting the following error:
Cross-thread operation not valid: Control 'labelX' accessed from a thread other than the thread it was created on.
How I do this? Thanks in advance!