C#代码调用参数计数不匹配

时间:2017-03-20 09:41:17

标签: c#

有人检查我的代码吗? 它显示参数计数剂量不匹配。

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

1 个答案:

答案 0 :(得分: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
    {
    }
}

在给定的情况下,您不可能错过任何参数(只需重新传递它们)。