C# How to invoke with more than one parameter

Ivan Prodanov picture Ivan Prodanov · Apr 8, 2009 · Viewed 24.4k times · Source

I use the code below to access the properties on my form,but today I'd like to write stuff to a ListView,which requires more parameters.

    public string TextValue
    {
        set
        {
            if (this.Memo.InvokeRequired)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.Memo.Text += value + "\n";
                });
            }
            else
            {
                this.Memo.Text += value + "\n";
            }
        }
    }

How to add more than one parameter and how to use them(value,value)?

Answer

Marc Gravell picture Marc Gravell · Apr 8, 2009

(edit - I think I misunderstood the original question)

Simply make it a method instead of a property:

public void DoSomething(string foo, int bar)
{
    if (this.InvokeRequired) {
        this.Invoke((MethodInvoker)delegate {
            DoSomething(foo,bar);
        });
        return;
    }
    // do something with foo and bar
    this.Text = foo;
    Console.WriteLine(bar);
}