gpt4 book ai didi

c# - 跨线程操作无效: Control 'statusStrip' accessed from a thread other than the thread it was created on

转载 作者:行者123 更新时间:2023-12-03 13:16:01 25 4
gpt4 key购买 nike

我已经尝试过了。
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在后台运行的方法。

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."));

关于c# - 跨线程操作无效: Control 'statusStrip' accessed from a thread other than the thread it was created on,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29008497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com