C# How to invoke with more than one parameter

25,744

(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);
}
Share:
25,744
P. Duw
Author by

P. Duw

Updated on July 22, 2022

Comments

  • P. Duw
    P. Duw almost 2 years

    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)?