Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            WFAppHost.ConfigureBootstrap(false);
            AppHost.CheckPortable(args);
            Logger.Init(AppHost.GetLogFilename());
            LogSysInfo();

            Application.ThreadException += ExExceptionHandler;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionsHandler;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (SingleInstanceTracker tracker = new SingleInstanceTracker(GKData.APP_TITLE, GetSingleInstanceEnforcer)) {
                if (tracker.IsFirstInstance)
                {
                    AppHost.InitSettings();
                    try {
                        var appHost = (WFAppHost)AppHost.Instance;
                        appHost.Init(args, false);

                        Application.Run(appHost.AppContext);
                    } finally {
                        AppHost.DoneSettings();
                    }
                }
                else
                {
                    tracker.SendMessageToFirstInstance(args);
                }
            }
        }
Ejemplo n.º 2
0
        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 Test_Common()
        {
            //Assert.Throws(typeof(ArgumentNullException), () => { new SingleInstanceProxy(null); });

            string[] args = new string[1];

            using (SingleInstanceTracker tracker = new SingleInstanceTracker("test", GetSingleInstanceEnforcer)) {
                Assert.IsNotNull(tracker.Enforcer);

                if (tracker.IsFirstInstance)
                {
                }
                else
                {
                    tracker.SendMessageToFirstInstance(args);
                }
            }
        }
Ejemplo n.º 4
0
        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();
                }
            }
        }
Ejemplo n.º 5
0
Archivo: App.cs Proyecto: tbayart/dndm
        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();
                }
            }
        }
Ejemplo n.º 6
0
        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();
                }
            }
        }
Ejemplo n.º 7
0
        public void Start(string[] args)
        {
            // Initialize IPC
            try
            {
                tracker = new SingleInstanceTracker <IPCConnectionWebSocket>();
                tracker.MessageReceived += (sender, e) => {
                    if (e.Message.Parameters.Length > 0 && e.Message.Parameters[0] == "newargs")
                    {
                        MainWindow.OnArgsReceived(e.Message.Parameters.Skip(1).ToArray());
                    }
                };
                if (tracker.IsFirstInstance)
                {
                    // Initialize GTK#
                    Application.Init();

                    TrayIcon = CreateTray(new Pixbuf(System.IO.File.ReadAllBytes("icon.png")));

                    // Create a Window with title
                    MainWindow = new MainWindow();

                    // Show the main window and start the application.
                    MainWindow.ShowAll();

                    if (Array.IndexOf <string>(args, "/as") >= 0)
                    {
                        MainWindow.Visible = false;
                    }

                    MainWindow.Realized += (sender, ea) =>
                    {
                        InitExtensions();

                        if (args.Length > 0)
                        {
                            ((MainWindow)MainWindow).OnArgsReceived(args);
                        }
                    };

                    MainWindow.DeleteEvent += (sender, ea) =>
                    {
                        MainWindow.HideOnDelete();
                    };
                    MainWindow.Destroyed += (sender, eventArgs) => { Settings.Default.Save(); Application.Quit(); }; // persist settings and quit
                    Application.Run();
                }
                else
                {
                    tracker.SendMessageToFirstInstance(args);
                }
            }catch (SingleInstancingException ex) {
                var dlg = new Gtk.MessageDialog(null, 0, MessageType.Error, ButtonsType.Ok, "Could not create a SingleInstanceTracker object:\n" + ex.Message + "\nInner Exception:\n" + ex.InnerException?.ToString() + "\nApplication will now terminate.");
                dlg.DeleteEvent += (o, ea) => {
                    Application.Quit();
                };
                dlg.Show();
                Application.Run();
            }finally{
                Dispose();
            }
        }