Add csharp
This commit is contained in:
11
csharp
Normal file
11
csharp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// Threading in C# - Invoking Methods (if required)
|
||||||
|
public static void InvokeIfRequired(this Control c, Action a) {
|
||||||
|
if (c.InvokeRequired) {
|
||||||
|
c.Invoke(new MethodInvoker(() => { InvokeIfRequired(c, a); }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (!c.IsHandleCreated) { IntPtr i = c.Handle; } // See links above - handle is not created, will cause cross-thread exceptions
|
||||||
|
a.Invoke();
|
||||||
|
} catch (Exception ex) { }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user