StealthRT
StealthRT

Reputation: 10542

Invoke MethodInvoker Delegate for more than 1 item at a time

The code below works just fine but I am looking for a way to combine all 3 into just one invoke statement:

this.Invoke(new MethodInvoker(delegate () {
   String.Format(
       "------------------------------------------------------------")
   );
}));

this.Invoke(new MethodInvoker(delegate () {
   String.Format(
       "- END " + archiveFullName + " -"
   );
}));

this.Invoke(new MethodInvoker(delegate () {
   String.Format(
       "------------------------------------------------------------")
   );
}));

I've already tried:

this.Invoke(new MethodInvoker(delegate () {
   listBox1.Items.Add(
      this.listBox1.Items.Add("--------------------------------------------------------")
      this.listBox1.Items.Add("- END " + archiveFullName + " -")
      this.listBox1.Items.Add("-------------------------------------------------------")
   );
}));

But that does not seem to work.

Any resolution would be great!

Upvotes: 0

Views: 719

Answers (1)

kennyzx
kennyzx

Reputation: 12993

Use the AddRange method.

listBox1.Items.AddRange(...

Upvotes: 1

Related Questions