2017-03-20 67 views
-4

是否有人檢查我的代碼? 它顯示參數計數劑量不匹配。C#代碼調用參數count dosen't match

void WriteFaceLog(string userID, string faceId, string size, string valid, string template) 
    { 
     if (lstvFace.InvokeRequired) 
     { 
      Action<string, string, string, string, string> action = WriteFaceLog; 
      this.Invoke(action, faceId, size, valid, template); 
     } 
     else 
     { 
      ListViewItem item = new ListViewItem(userID); 
      item.SubItems.AddRange(new[] { faceId, size, valid, template }); 
      lstvFace.Items.Add(item); 
     } 
    } 
+2

您錯過'Invoke'中的'userId'。 – Sinatr

回答

0

典型自動調用模式(旨在簡化從任何線程運行的方法)將看起來像這樣在你的情況:

void WriteFaceLog(string userID, string faceId, string size, string valid, string template) 
{ 
    if (this.InvokeRequired) // you can use lstvFace instead of this, it doesn't matter as both are in same thread, you can also omit this 
     this.Invoke((MethodInvoker)delegate { WriteFaceLog(userID, faceId, size, valid, template); }); 
    else 
    { 
    } 
} 

在給定的情況下,你不可能錯過任何一個參數(只重新通過它們)。