static void Main(String[] args) { SingleInstanceTracker tracker = null; try { tracker = new SingleInstanceTracker("LogViewUtil", new SingleInstanceEnforcerRetriever(GetSingleInstanceEnforcer), args); if (tracker.IsFirstInstance) { Application.Run((MainForm)tracker.Enforcer); } else { tracker.SendMessageToFirstInstance(args); } } catch (SingleInstancingException ex) { if (!WorkaroundForInitialInstance(args)) { MessageBox.Show(String.Join(Environment.NewLine, args) + Environment.NewLine + ex.ToString()); } } finally { if (tracker != null) { tracker.Dispose(); } } }
public void StartSingleInstance(string[] args) { try { // Attempt to create a tracker tracker = new SingleInstanceTracker("SingleInstanceSample", new SingleInstanceEnforcerRetriever(GetSingleInstanceEnforcer)); // If this is the first instance of the application, run the main form if (tracker.IsFirstInstance) { try { frmMain form = (frmMain)tracker.Enforcer; form.CallBackWinAppWebBrowser(); form.InitMouseKeyBoardEvent(); Xpcom.Initialize("Firefox"); if (Array.IndexOf <string>(args, "/as") >= 0) { form.WindowState = FormWindowState.Minimized; } form.Load += delegate(object sender, EventArgs e) { form.FormLoad(); if (form.WindowState == FormWindowState.Minimized) { form.HideForm(); } if (args.Length > 0) { form.OnMessageReceived(new MessageEventArgs(args)); } }; form.FormClosing += delegate(object sender, FormClosingEventArgs e) { form.exit(); Dispose(); }; Application.Run(form); } finally { Dispose(); } } else { // This is not the first instance of the application, so do nothing but send a message to the first instance if (args.Length > 0) { tracker.SendMessageToFirstInstance(args); } } } catch (SingleInstancingException ex) { MessageBox.Show("Could not create a SingleInstanceTracker object:\n" + ex.Message + "\nApplication will now terminate.\n" + ex.InnerException.ToString()); return; } finally { if (tracker != null) { tracker.Dispose(); } } }
public void Start(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { // Attempt to create a tracker tracker = new SingleInstanceTracker("SingleInstanceSample", new SingleInstanceEnforcerRetriever(GetSingleInstanceEnforcer)); // If this is the first instance of the application, run the main form if (tracker.IsFirstInstance) { try { NewDownloadForm df = null; MainForm form = (MainForm)tracker.Enforcer; if (args.Length > 0) { //form.downloadList1.AddDownloadURLs(ResourceLocation.FromURLArray(args), 1, null, 0); CommandLineArguments argstruct = new CommandLineArguments(); argstruct.ParseArguments(args); if (argstruct.StartMinimized == true) { form.WindowState = FormWindowState.Minimized; } //DownloadManager.Instance.Add(ResourceLocation.FromURL(argstruct.File), null, Path.Combine(argstruct.path, Path.GetFileName(argstruct.File)), argstruct.Segments, true); // form.downloadList1.AddDownloadURLs(ResourceLocation.FromURL(argstruct.File), argstruct.Segments, argstruct.path, 0); if (argstruct.File != null) { df = new NewDownloadForm(argstruct.File, Path.GetFileName(argstruct.File), argstruct.path, argstruct.Segments, argstruct.username, argstruct.password); df.Show(); df.Focus(); df.BringToFront(); } } form.Load += delegate(object sender, EventArgs e) { InitExtensions(); if (form.WindowState == FormWindowState.Minimized) { form.HideForm(); } /*if (args.Length > 0) * { * form.OnMessageReceived(new MessageEventArgs(args)); * }*/ }; form.FormClosing += delegate(object sender, FormClosingEventArgs e) { Dispose(); }; Application.Run(form); } finally { Dispose(); } } else { // This is not the first instance of the application, so do nothing but send a message to the first instance if (args.Length > 0) { tracker.SendMessageToFirstInstance(args); } } } catch (SingleInstancingException ex) { MessageBox.Show("Could not create a SingleInstanceTracker object:\n" + ex.Message + "\nApplication will now terminate.\n" + ex.InnerException.ToString()); return; } finally { if (tracker != null) { tracker.Dispose(); } } }
public void Start(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { // Attempt to create a tracker tracker = new SingleInstanceTracker("SingleInstanceSample", new SingleInstanceEnforcerRetriever(GetSingleInstanceEnforcer)); // If this is the first instance of the application, run the main form if (tracker.IsFirstInstance) { try { MainForm form = (MainForm)tracker.Enforcer; //form.downloadList1.AddDownloadURLs(ResourceLocation.FromURLArray(args), 1, null, 0); if (Array.IndexOf <string>(args, "/as") >= 0) { form.WindowState = FormWindowState.Minimized; } form.Load += delegate(object sender, EventArgs e) { InitExtensions(); if (form.WindowState == FormWindowState.Minimized) { form.HideForm(); } if (args.Length > 0) { form.OnMessageReceived(new MessageEventArgs(args)); } }; form.FormClosing += delegate(object sender, FormClosingEventArgs e) { Dispose(); }; Application.Run(form); } finally { Dispose(); } } else { // This is not the first instance of the application, so do nothing but send a message to the first instance if (args.Length > 0) { tracker.SendMessageToFirstInstance(args); } } } catch (SingleInstancingException ex) { MessageBox.Show("Could not create a SingleInstanceTracker object:\n" + ex.Message + "\nApplication will now terminate.\n" + ex.InnerException.ToString()); return; } finally { if (tracker != null) { tracker.Dispose(); } } }