I\'ve this little method which is supposed to be thread safe. Everything works till i want it to have return value instead of void. How do i get the return value when BeginI
You have to Invoke() so you can wait for the function to return and obtain its return value. You'll also need another delegate type. This ought to work:
public static string readControlText(Control varControl) {
if (varControl.InvokeRequired) {
return (string)varControl.Invoke(
new Func(() => readControlText(varControl))
);
}
else {
string varText = varControl.Text;
return varText;
}
}