Last active
August 29, 2015 14:01
-
-
Save AlexArchive/724b6708d24defc910f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ControlExtensions | |
| { | |
| public static void Invoke(this Control control, MethodInvoker method) | |
| { | |
| if (control.InvokeRequired == false) | |
| { | |
| // The executing thread _is_ the thread that owns the control's underlying | |
| // handle and as such, there is no need to marshall the method invocation. | |
| method.Invoke(); | |
| } | |
| else | |
| { | |
| control.Invoke(method); | |
| } | |
| } | |
| public static void BeginInvoke(this Control control, MethodInvoker method) | |
| { | |
| if (control.InvokeRequired == false) | |
| { | |
| // The executing thread _is_ the thread that owns the control's underlying | |
| // handle and as such, there is no need to marshall the method invocation. | |
| method.Invoke(); | |
| } | |
| else | |
| { | |
| control.BeginInvoke(method); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment