可能ですか?たとえば、スレッドの実行時にラベルに新しい値を設定する必要があります。
私はこれを試してみました:スレッド実行中のラベルに新しい値を設定する
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;
}
}
}
);
}
私は次のようなエラーになっている:私はこれを行う方法
Cross-thread operation not valid: Control 'labelX' accessed from a thread other than the thread it was created on.
を?前もって感謝します!
可能なdup? http://stackoverflow.com/questions/661561/how-to-update-gui-from-another-thread-in-c – gbianchi