【发布时间】:2015-05-14 12:49:03
【问题描述】:
我试过这个。 https://stackoverflow.com/a/142069/2126472
点赞toolStripStatusLabel1.InvokeRequired
但是toolStripStatusLabel1 没有InvokeRequired
我也试过这个。 https://stackoverflow.com/a/15831292/2126472
它的错误就像无效的参数一样
SetTextCallback d = new SetTextCallback(SetText);
form.Invoke(d, new object[] { form, ctrl, text });
当我使用
ThreadHelperClass.SetText(this, toolStripStatusLabel1, "This text was set safely.");
但当我使用textBox时不会出错
我的代码有方法等待bool 来自另一个使用线程在后台运行的方法。
Thread t = new Thread(TestRemoteDB);
t.Start();
// In TestRemoteDB() will call updateRemoteDBStatus()
喜欢这个
private void updateRemoteDBStatus(bool successful)
{
if (successful)
{
toolStripStatusLabel4.Text = "OK!";
toolStripStatusLabel4.ForeColor = Color.Green;
}
else
{
toolStripStatusLabel4.Text = "Error!";
toolStripStatusLabel4.ForeColor = Color.Red;
}
}
【问题讨论】:
-
你能粘贴你的完整代码吗
标签: c# multithreading winforms