Kan*_*kit 1 c# multithreading winforms
我试过这个。 /sf/answers/9944861/
喜欢 toolStripStatusLabel1.InvokeRequired
但toolStripStatusLabel1没有InvokeRequired
我也试过这个。 /sf/answers/1108190471/
它像无效参数一样出错
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()
Run Code Online (Sandbox Code Playgroud)
像这样
private void updateRemoteDBStatus(bool successful)
{
if (successful)
{
toolStripStatusLabel4.Text = "OK!";
toolStripStatusLabel4.ForeColor = Color.Green;
}
else
{
toolStripStatusLabel4.Text = "Error!";
toolStripStatusLabel4.ForeColor = Color.Red;
}
}
Run Code Online (Sandbox Code Playgroud)
尝试这个:
this.BeginInvoke((Action)(() => toolStripStatusLabel1.Text = "This text was set safely."));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1637 次 |
| 最近记录: |