private static void RunApp(string[] arg) { Process[] runningProcesses = Process.GetProcessesByName("eAd Client"); if (runningProcesses.Length <= 1) { System.Diagnostics.Trace.Listeners.Add(new ClientTraceListener()); System.Diagnostics.Trace.AutoFlush = false; try { if (arg.GetLength(0) > 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); System.Diagnostics.Trace.WriteLine(new LogMessage("Main", "Options Started"), LogType.Info.ToString()); Form formMain = new OptionForm(); Application.Run(formMain); } else { bool createdNew = true; new Mutex(true, "UniqueApplicationName", out createdNew); if (createdNew) { Splasher.Splash = new SplashScreen(); Splasher.ShowSplash(); Trace.WriteLine(new LogMessage("Main", "Client Started"), LogType.Info.ToString()); App app = new App(); app.Run(); } } } catch (Exception ex) { HandleUnhandledException(ex); } // Catch unhandled exceptions AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); // Always flush at the end System.Diagnostics.Trace.WriteLine(new LogMessage("Main", "Application Finished"), LogType.Info.ToString()); System.Diagnostics.Trace.Flush(); } else { ShowWindowAsync(runningProcesses[0].MainWindowHandle, 6); ShowWindowAsync(runningProcesses[0].MainWindowHandle, 9); } }
private static void RunApp(string[] arg) { Process[] processesByName = Process.GetProcessesByName("eAd Client"); if (processesByName.Length <= 1) { Trace.Listeners.Add(new ClientTraceListener()); Trace.AutoFlush = false; try { if (arg.GetLength(0) > 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Trace.WriteLine(new LogMessage("Main", "Options Started"), LogType.Info.ToString()); Form mainForm = new global::ClientApp.OptionForm(); Application.Run(mainForm); } else { bool createdNew = true; new Mutex(true, "UniqueApplicationName", out createdNew); if (createdNew) { Splasher.Splash = new SplashScreen(); Splasher.ShowSplash(); Trace.WriteLine(new LogMessage("Main", "Client Started"), LogType.Info.ToString()); new App().Run(); } } } catch (Exception exception) { HandleUnhandledException(exception); } AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Startup.CurrentDomain_UnhandledException); Application.ThreadException += new ThreadExceptionEventHandler(Startup.Application_ThreadException); Trace.WriteLine(new LogMessage("Main", "Application Finished"), LogType.Info.ToString()); Trace.Flush(); } else { ShowWindowAsync(processesByName[0].MainWindowHandle, 6); ShowWindowAsync(processesByName[0].MainWindowHandle, 9); } }