【发布时间】:2013-10-17 11:57:43
【问题描述】:
我正在尝试使用不同的线程更新 UI 并使用以下过程来执行此操作。但在调用期间出现上述错误。请告知这是不允许的。
delegate void SetLabelCallback(string text,string Qmgr);
private void Set_status(string text, string Qmgr)
{
if (this.Status1A.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(record_count);
this.Invoke(d, new object[] { text,Qmgr });
}
else
{
switch (Qmgr)
{
case "GCSSPR1A": this.Status1A.Text = text;
break;
case "GCSSPR1B": this.B1_Status.Text = text;
break;
case "GCSSPR2A": this.A2_Status.Text = text;
break;
case "GCSSPR2B": this.B2_Status.Text = text;
break;
case "GCSSPR3A": this.A3_Status.Text = text;
break;
case "GCSSPR3B": this.B3_Status.Text = text;
break;
}
}
【问题讨论】:
-
record_count的定义是什么? -
您使用的是 C# 4 吗?如果是这样,你可以让这段代码更简单,更不容易出错。
-
我的代码中的错字已修复...
-
只是出于兴趣,是否有更长的异常消息allin 小写? :)
标签: c# multithreading winforms invoke