MethodInvoker mi = new MethodInvoker(() => progressBar.Progress = newProgressValue);
if (progressBar.InvokeRequired)
{
progressBar.Invoke(mi);
}
else
{
mi.Invoke();
}
This code belongs in the lengthy task. See:
- InvokeRequired
- Invoke
- Delegates
Lambda is just an over-fancy word for a function (or method) that is declared inline instead of as a method on class or as a raw function in languages that support them. It's "anonymous" if you don't assign it to a named variable. Be careful because they "Capture" the variables needed by them and can behave a bit strangely if you don't understand them.
The syntax for lambdas is pretty easy: () => someValue;
is pretty much the same as public void SomeMethod() { return someValue; }
put things into the parentheses to add parameters to the lambda. If you only have one parameter, feel free to skip the parentheses.