public static void Launch() { if (ProgramUtils.IsRuningOnWindows()) { ProgramUtils.FreeConsole(); } Thread staThread = new Thread(obj => { Application.ThreadException += ThreadExceptionCallbackFun; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm form = new MainForm(); Application.Run(form); }); staThread.SetApartmentState(ApartmentState.STA); staThread.Start(); }