Created
December 22, 2014 06:30
-
-
Save melvinlee/dd5b8032be63495a7276 to your computer and use it in GitHub Desktop.
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
/************************************************************************************** | |
Version: 1.0.1 | |
Delegate Extension Methods | |
***************************************************************************************/ | |
using System; | |
using System.Windows.Forms; | |
public static class ControlExtension | |
{ | |
public static void BeginInvokeAction(this Control control, Action action) | |
{ | |
if (control.IsDisposed || (!control.IsHandleCreated && !control.FindForm().IsHandleCreated)) | |
{ | |
// some exceptional condition: | |
// handle in whatever way is appropriate for your app | |
return; | |
} | |
if (control.InvokeRequired) | |
control.BeginInvoke(new MethodInvoker(action)); | |
else | |
action.Invoke(); | |
} | |
public static void BeginInvokeAction(this Control control, params Action[] actions) | |
{ | |
if (control.IsDisposed || (!control.IsHandleCreated && !control.FindForm().IsHandleCreated)) | |
{ | |
// some exceptional condition: | |
// handle in whatever way is appropriate for your app | |
return; | |
} | |
foreach (var action in actions) | |
{ | |
if (control.InvokeRequired) | |
control.BeginInvoke(new MethodInvoker(action)); | |
else | |
action.Invoke(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment