2013-10-17 196 views
0

我试图用不同的线程更新UI,并使用下面的过程中做so.But调用期间获得上述错误。请注意,这是不允许的。system.reflection.targetparametercountexception参数数量不匹配参数数量不匹配

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; 
      } 

     } 
+0

什么是'record_count'的定义是什么? –

+0

你使用C#4吗?如果是这样,你可以使这个代码更简单,更不容易出错。 – Baldrick

+0

错字在我的代码固定它... – user2772983

回答

0

试着改变你的函数的顶部是这样的:

private void Set_status(string text, string Qmgr) 
{ 
    if (this.Status1A.InvokeRequired) 
    { 
     this.Invoke((Action)(() => Set_status(text, Qmgr))); 
    } 
    else 
    { 

这样,你不应该需要委托声明等

1

我也会做同样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 }); 

我希望有帮助。

+0

“的在委托处理程序/函数调用的参数的数量,并在调用声明中定义的对象的数量之间的失配”。 + 1 – Dave

相关问题