From 78f6339f39c32ab8a5855051b47376d58af201a9 Mon Sep 17 00:00:00 2001 From: Russ Kollmansberger Date: Fri, 19 Jul 2024 08:33:42 -0500 Subject: [PATCH] Add csharp --- csharp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 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