C# system.reflection.targetparametercountexception参数计数不匹配参数计数不匹配
我正在尝试使用不同的线程更新UI,并使用下面的过程来更新UI。但是在调用过程中出现上述错误。这是不允许的C# system.reflection.targetparametercountexception参数计数不匹配参数计数不匹配,c#,multithreading,winforms,invoke,C#,Multithreading,Winforms,Invoke,我正在尝试使用不同的线程更新UI,并使用下面的过程来更新UI。但是在调用过程中出现上述错误。这是不允许的 delegate void SetLabelCallback(string text,string Qmgr); private void Set_status(string text, string Qmgr) { if (this.Status1A.InvokeRequired) { SetTextCallb
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;
}
}
尝试将函数顶部更改为以下内容:
private void Set_status(string text, string Qmgr)
{
if (this.Status1A.InvokeRequired)
{
this.Invoke((Action)(() => Set_status(text, Qmgr)));
}
else
{
这样,您就不需要委托声明等了。我也会像Baldrick那样做 他用的是lambda表达式,也许你会用这样的
private void Set_status(string text, string Qmgr)
{
if (this.InvokeRequired)
{
this.Invoke(new ReceivedEventHandler(Set_status), new Object[] {text, Qmgr});
}
else
{
}
}
但是,我认为这不是问题所在
以前,当委托处理程序/函数调用中的参数数量与调用声明中定义的对象数量不匹配时,我收到了这个问题
this.Invoke(d, new object[] { text, Qmgr, something_missing });
我希望这能有所帮助。记录计数的定义是什么?您使用的是C 4吗?如果是这样的话,您可以使这段代码更简单,更不容易出错。我的代码中的输入错误修复了它…只是出于兴趣,是否存在一个甚至更长的异常消息AllinLowerCase?:)“委托处理程序/函数调用中的参数数量与调用声明中定义的对象数量不匹配。”+1