Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
スタックトレースを握りつぶさないよう頑張ってみたControl.Invoke拡張メソッド cf. http://www2.hatenadiary.jp/entry/2014/06/03/003344
public static class ControlInvokerEx
{
public static object InvokeEx(this Control ctl, Delegate act)
{
return InvokeEx(ctl,act,null);
}
public static object InvokeEx(this Control ctl, Delegate act,params object[] args)
{
if (!ctl.InvokeRequired)
return act.DynamicInvoke(args);
Exception exp = null;
var ret = ctl.Invoke((MethodInvoker)(() =>
{
try
{
act.DynamicInvoke(args);
}
catch (Exception ex)
{
exp = ex;
}
}));
if (exp != null)
throw new System.Reflection.TargetInvocationException(exp);
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment