I have no issues invoking actions on UI controls through BeginInvoke and such, however, that’s a void method. I need to get a value from a textbox for use in a different thread.
How can I accomplish this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The simplest solution is to capture a local variable in a closure.
The compiler will generate some code that is much like chibacity’s solution – the local variable becomes a field of a compiler-generated class.
UPDATE
This does not work – the lambda expression is not assignable to
Delegate. This problem can be solved using an extension method.The usage is then as follows.
It is possible to stuff multiple statements into the lambda expression.
But as chibacity already mentioned in a comment it may be better to explicitly write a method. Beyond a certain point using lambda expressions will adversely affect the readability of the code. And using lambda expressions is of course very prone to introducing repeated code.