Exemplo n.º 1
0
            public static void Run(Form f, StartupNextInstanceEventHandler startupHandler)
            {
                SingleInstanceApplication app = new SingleInstanceApplication();
                app.MainForm = f;
                app.StartupNextInstance += startupHandler;

                Options options = new Options();

                if (!CommandLine.Parser.Default.ParseArguments(Environment.GetCommandLineArgs(), options))
                    Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);

                app.Startup += new StartupEventHandler(((Main)f).Init);

                app.Run(Environment.GetCommandLineArgs());
            }
Exemplo n.º 2
0
        private static void NewInstanceHandler(object sender, StartupNextInstanceEventArgs e)
        {
            Options options = new Options();

            string[] args = new string[e.CommandLine.Count];
            for (int i = 0; i < e.CommandLine.Count; i++)
                args[i] = e.CommandLine[i];
            if (!CommandLine.Parser.Default.ParseArguments(args, options))
                return;

            SingleInstanceApplication app = (SingleInstanceApplication)sender;
            foreach (Form form in app.OpenForms)
            {
                if (form.Name == "Main")
                {
                    ((Main)form).HandleNewInstance(options);
                    break;
                }
            }
        }
 /// <summary>
 /// <para>Handles the argument options that were passed to a new instance of this application</para>
 /// </summary>
 /// <param name="options"></param>
 public void HandleNewInstance(Options options)
 {
     if (options.Trigger != null && OnCommandLineTrigger != null)
         OnCommandLineTrigger(this, new Events.EventArgsValue<string>(options.Trigger));
 }