0

I saw one program that was about synchrony and using threads. In one part of the program, I saw this lambda expression and I got confused.

for (int i = 0; i < 100; i++)
{
  Thread.Sleep(100);
  progressBar1.BeginInvoke(new Action(() =>
  {
    progressBar1.Value = i;
    listBox1.Items.Add(i.ToString());
  }));
}

My question is, why this lambda expression doesn't have any input argument?

1
  • Threads (by default) doesn't get any input argument(implicitly) also doesn't return anything Commented Jul 17, 2013 at 9:13

2 Answers 2

1

In the Control.BeginInvoke method's description there is written:

// Summary:
//     Executes the specified delegate asynchronously on the 
//     thread that the control'sunderlying handle was created on.
//
// Parameters:
//   method:
//     A delegate to a method that takes no parameters.

From the Action Delegate MS article:

Encapsulates a method that has no parameters and does not return a value.

Sign up to request clarification or add additional context in comments.

Comments

1

The goal here is to execute some statements which access the UI on the UI thread. The action doesn't need any input (i, progressBar1 and listBox1 are captured) and doesn't have an output, only side effects (modifying the UI).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.