public static void UIThread(this System.Windows.Forms.Control form, MethodInvoker code) { if (form.InvokeRequired) { form.Invoke(code); return; } code.Invoke(); }