Beispiel #1
0
        /// <summary>
        /// Called when the first instance is created
        /// </summary>
        /// <param name="e">Contains command line parameters</param>
        /// <returns>A System.Boolean that indicates if the application should continue starting up.</returns>
        protected override bool OnStartup(StartupEventArgs e)
        {
            Trace.AutoFlush = true;

            // Start the first instance of this app
            _wpfApp = new WpfApplication()
            {
                ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown
            };

            // Start a background thread for the named pipe server:
            Task.Run(() => _wpfApp.NamedPipeServer());

            if (e.CommandLine.Count > 0)
            {
                try
                {
                    var instanceParams = CgbUtils.ParseCommandLineArgs(e.CommandLine.ToArray());
                    _wpfApp.HandleNewInvocation(instanceParams);
                }
                catch (Exception ex)
                {
                    _wpfApp.AddToMessagesList(Message.Create(MessageType.Error, ex.Message, null));                     // TODO: Window with more info?
                    _wpfApp.ShowMessagesList();
                }
            }
            _wpfApp.Run();
            return(false);
        }
 /// <summary>
 /// The application is already running, but we're receiving new command line parameters to be handled...
 /// </summary>
 /// <param name="e">Contains the command line parameters, passed by the invoker</param>
 protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e)
 {
     if (e.CommandLine.Count > 0)
     {
         try
         {
             var instanceParams = CgbUtils.ParseCommandLineArgs(e.CommandLine.ToArray());
             _wpfApp.HandleNewInvocation(instanceParams);
         }
         catch (Exception ex)
         {
             _wpfApp.AddToMessagesList(Message.Create(MessageType.Error, ex.Message, null));                     // TODO: Window with more info?
             _wpfApp.ShowMessagesList();
         }
     }
 }