static class StaticClass
{
public static void SafeThreadAction<T>(this T form, Action<T> call) where T : System.Windows.Forms.Form
{
form.BeginInvoke(call, form);
}
public static Y SafeThreadGet<T, Y>(this T form, Func<T, Y> call) where T : System.Windows.Forms.Form
{
IAsyncResult result = form.BeginInvoke(call, form);
object result2 = form.EndInvoke(result);
return (Y)result2;
}
}
Example - Calls
StaticClass
.SafeThreadAction(this, frm => frm.txtCaseCount.Text = "count 2");
string
textboxtext = StaticClass.SafeThreadGet(this, frm => frm.txtCaseCount.Text);