private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); frm_Main mainform = new frm_Main(); if (Environment.CommandLine.ToLower().Contains("autoRun".ToLower())) { string address = Path.GetDirectoryName(Application.ExecutablePath); if (address != null) { Process.Start( new ProcessStartInfo(Application.ExecutablePath, "/auto_Corrected_Run") { WorkingDirectory = address, UseShellExecute = true }); } Environment.Exit(0); } if (Environment.CommandLine.ToLower().Contains("auto_Corrected_Run".ToLower())) { mainform.IsAutoRun = true; } try { SingleInstanceApplication.Run(mainform, StartupNextInstanceHandler); } catch (Exception) { Application.Run(mainform); } }
private static void StartupNextInstanceHandler(object sender, StartupNextInstanceEventArgs e) { frm_Main form = Application.OpenForms[0] as frm_Main; if (form != null) { if (!form.Visible) { form.Visible = true; } form.Activate(); } }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var mainForm = new frm_Main(); if (Environment.CommandLine.ToLower().Contains("autoRun".ToLower())) { var address = Path.GetDirectoryName(Application.ExecutablePath); if (address != null) { Process.Start( new ProcessStartInfo(Application.ExecutablePath, "/auto_Corrected_Run") { WorkingDirectory = address, UseShellExecute = true }); } Environment.Exit(0); } if (Environment.CommandLine.ToLower().Contains("auto_Corrected_Run".ToLower())) { mainForm.IsAutoRun = true; } try { SingleInstanceApplication.Run(mainForm, StartupNextInstanceHandler); } catch (Exception e) { Application.Run(mainForm); } }