Exemplo n.º 1
0
        /// <summary>
        /// Processes an unhandled exception occurred in the UI thread.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            var exception = e.Exception as Exception;

            MyLogger.Log("Unhandled exception.", exception);
            if (ConfirmUnhandledException(exception, "UI Thread"))
            {
                e.Handled = true;
            }
            else
            {
                SingleAppInstanceHelper.Exit();
                Environment.Exit(1);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes an unhandled exception occurred in a background task.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
        {
            var exception = e.Exception.InnerException as Exception;

            MyLogger.Log("Unhandled exception.", exception);
            if (ConfirmUnhandledException(exception, "Background Task"))
            {
                e.SetObserved();
            }
            else
            {
                SingleAppInstanceHelper.Exit();
                Environment.Exit(1);
            }
        }
Exemplo n.º 3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ArgumentsHelper.SetArgs(e.Args);
            base.OnStartup(e);

            // Local method to enqueue connections specified with command-line argument
            bool EnqueueOpenRequestedConnections(IProcessCommander processCommander)
            {
                if (!ArgumentsHelper.HasConnectionSpecified)
                {
                    return(false);
                }
                foreach (var conn in ArgumentsHelper.SpecifiedConnections)
                {
                    MyLogger.Log($"Connection (Type: {conn.Type}, Id: {conn.ConnectionId}) has been enqueued.");
                    processCommander.Invoke(conn.Type, conn.ConnectionId);
                }
                return(true);
            }

            if (SingleAppInstanceHelper.TryStart())
            {
                // Boot as an IPC host
                var service = new ProcessCommander
                {
                    ConnectionRequest = ConnectionRequest.Singleton,
                };
                var serviceHost = IPCService.OpenServiceHost(service);
                EnqueueOpenRequestedConnections(service);
            }
            else
            {
                // Boot as an IPC client
                var channel = IPCService.CreateServiceChannel();
                if (!EnqueueOpenRequestedConnections(channel))
                {
                    MyLogger.Log("Shutting down because another application instance has already run...");
                }
                channel.Activate();
                // Shutdown after activate the primary window
                Shutdown();
            }
        }
Exemplo n.º 4
0
 protected override void OnExit(ExitEventArgs e)
 {
     base.OnExit(e);
     SingleAppInstanceHelper.Exit();
 }