Is there any extension method available for resolving cross thread exception in windows forms like the one which is there for wpf forms.or any general pattern..
http://www.codeproject.com/Articles/37314/Use开发者_运维知识库ful-WPF-Threading-Extension-Method.aspx
Invoke
already does some things to short-circuit here, but it would be trivial to make it complete:
public static class SyncExtensions {
public static void InvokeIfRequired(this ISynchronizeInvoke ctrl,
MethodInvoker method) {
if(ctrl.InvokeRequired) ctrl.Invoke(method, null);
else method();
}
}
The choice of MethodInvoker
is since this has specific handling inside Invoke
to avoid having to use DynamicInvoke
(reflection).
Did you take a look at the BeginInvoke Method?
精彩评论