commit 78f6339f39c32ab8a5855051b47376d58af201a9 Author: Russ Kollmansberger Date: Fri Jul 19 08:33:42 2024 -0500 Add csharp diff --git a/csharp b/csharp new file mode 100644 index 0000000..7c382d2 --- /dev/null +++ b/csharp @@ -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) { } +} \ No newline at end of file