-4

is there anyone check my code? it shows the parameter count dose not 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);
        }
    }
Jerry
  • 1

1 Answers1

0

The typical auto-invoke pattern (designed to simplify running method from any thread) will looks like this in your case:

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

In given case you are unlikely to miss any parameter (just re-pass them).

Sinatr
  • 20,892
  • 15
  • 90
  • 319