sách gpt4 ai đã đi

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

In lại 作者:行者123 更新时间:2023-12-03 13:16:01 26 4
mua khóa gpt4 Nike

我已经尝试过了。
https://stackoverflow.com/a/142069/2126472

toolStripStatusLabel1.InvokeRequired
NhưngtoolStripStatusLabel1KHÔNGInvokeRequired
我也尝试过
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;
}
khác
{
toolStripStatusLabel4.Text = "Error!";
toolStripStatusLabel4.ForeColor = Color.Red;
}
}

1 Câu trả lời

Hãy thử cách này:

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/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com