The simplest solution is to capture a local variable in the closure.
String text;
textBox.Invoke(() => text = textBox.Text);
The compiler will generate some code that is very similar to a chibacity solution - a local variable becomes the field of the class generated by the compiler.
UPDATE
- Delegate. .
internal void ExecuteOnOwningThread(this Control control, Action action)
{
if (control.InvokeRequired)
{
control.Invoke(action);
}
else
{
action();
}
}
.
String text;
textBox.ExecuteOnOwningThread(() => text = textBox.Text);
.
textBox.ExecuteOnOwningThread(() =>
{
DoStuff();
text = textBox.Text
DoOtherStuff();
});
, , . - . -, , .