![](/img/trans.png)
[英]Cross-thread operation not valid: Control 'listBox1' accessed from a thread other than the thread it was created on
[英]Cross-thread operation not valid: Control 'statusStrip' accessed from a thread other than the thread it was created on
我已经尝试过了。 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
时没有错误
我的代码具有等待使用Thread在后台运行的另一种方法的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;
}
}
尝试这个:
this.BeginInvoke((Action)(() => toolStripStatusLabel1.Text = "This text was set safely."));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.