/// <summary> /// Raises the <see cref="E:System.Windows.Application.Startup" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param> protected override void OnStartup(StartupEventArgs e) { Arguments = GetArguments(); ShutdownMode = ShutdownMode.OnMainWindowClose; Logger.Info("**********\n\n\nLauncher [{0}] is starting applet [{1}]", Launcher, AppletName); ApplicationHelper.EnableExceptionHandling(); // RegisterCloudApplet(); ComSink.Instance.StartAppletDeamon(AppletName, ID); ComSink.Instance.RegisterApplet(Launcher, AppletName, ID); if (Current.StartupUri != null) { return; } ShutdownMode = ShutdownMode.OnExplicitShutdown; var site = (IXProcAddInSite)Activator.GetObject(typeof(IXProcAddInSite), Ipc); // Register a server channel so that the host can make calls to IXProcAddIn. // (Client channels are generally registere automatically.) Logger.Info("\tRegistering Channel to [{0}]'", Ipc); string procName = Process.GetCurrentProcess().ProcessName; Logger.Info("Registering Applet Process Server Channel '{0}'", procName); IpcUtils.RegisterServerChannel(procName); //IpcUtils.RegisterServerChannel(QueryString); // Set up a watchdog thread to catch abnormal quitting of the host process. // For normal exist, IXProcAddIn.ShutDown() is expected to be called. bool normalExit = false; new Thread(new ThreadStart(delegate { Thread.CurrentThread.IsBackground = true; Process.GetProcessById(site.HostProcessId).WaitForExit(); if (normalExit) { return; } Logger.Warn("Host process quit unexpectedly."); Environment.Exit(2); })).Start(); CompositionHelper.ComposeParts(this, SourceType); if (Addin != null) { Logger.Info("Created Addin [{0}] for site {1}", Addin.GetType().Name, site.HostProcessId); Addin.Site = site; Dispatcher.Run(); normalExit = true; } else { Logger.Info("No Addin found in package, shutting down."); if (Current.ShutdownMode == ShutdownMode.OnMainWindowClose) { if (Current.MainWindow == null) { Current.MainWindow.Close(); } Current.Shutdown(); } else { Current.Shutdown(); } } }