Created
June 2, 2014 15:34
-
-
Save walkure/62ef05e33016b9439834 to your computer and use it in GitHub Desktop.
スタックトレースを握りつぶさないよう頑張ってみたControl.Invoke拡張メソッド cf. http://www2.hatenadiary.jp/entry/2014/06/03/003344
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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