internal void RunApplication(DocObjHost.ApplicationRunner runner) { EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordHosting, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DocObjHostRunApplicationStart); PresentationAppDomainManager.SaveAppDomain = true; this.EnableErrorPage(); if (runner()) { Invariant.Assert(PresentationAppDomainManager.NewAppDomain != null, "Failed to start the application in a new AppDomain"); Invariant.Assert(ApplicationProxyInternal.Current != null, "Unexpected reentrant PostShutdown?"); PresentationAppDomainManager presentationAppDomainManager = PresentationAppDomainManager.NewAppDomain.DomainManager as PresentationAppDomainManager; Invariant.Assert(ApplicationProxyInternal.Current == this._appProxyInternal, "AppProxyInternal has shut down unexpectedly."); this._appProxyInternal = presentationAppDomainManager.CreateApplicationProxyInternal(); PresentationAppDomainManager.SaveAppDomain = false; ApplicationProxyInternal.InitData value = this._initData.Value; value.HandleHistoryLoad = true; this._appProxyInternal.Run(value); this._initData.Value = null; } else { PresentationAppDomainManager.SaveAppDomain = false; } EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordHosting, EventTrace.Level.Verbose, EventTrace.Event.WpfHost_DocObjHostRunApplicationEnd); }
private object DoDownloadApplicationCompleted(object e) { EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WpfHost_DownloadApplicationEnd); DownloadApplicationCompletedEventArgs args = (DownloadApplicationCompletedEventArgs)e; ClearAsynchronousOperationStatus(); // Shutdown may have started and IBrowserCallbackServices may have become unavailable. // In particular, making calls to the browser, just like above, could cause a pending shutdown // call to be dispatched. if (IsShuttingDown) return null; if (args.Error != null) { // Synchronizing with AssertApplicationRequirementsAsync(). (If no error here, AAR must have // succeeded too.) IPHM could throw exceptions on both threads, in any order. We should // handle only one, and we prefer the one from AAR as it tends to be more meaningful, except // in the case when it's InvalidOperationException due to an error already encountered during // application download and IPHM getting set to a dead state internally. _assertAppRequirementsEvent.WaitOne(); if (!_assertAppRequirementsFailed) { HandleError(args.Error, args.LogFilePath, _getManifestCompletedEventArgs.SupportUri, null); } return null; } // Race condition: UserStop() can be called after InPlaceHostingManager has completed // the downloading but before our callback is called. bool canceled = _canceled || args.Cancelled; if (canceled) { HandleCancel(); return null; } SetStatusText(SR.Get(SRID.HostingStatusPreparingToRun)); // This is the last progress message set. It is cleared by // IBrowserCallbackServices.OnBeforeShowNavigationWindow() (in CColeDocument). // Go through the Dispatcher at a lower priority to allow the above status message to render. // There can be a signficant delay between the end of downloading and the rendering of the first // application page, especially on cold start. Dispatcher.BeginInvoke(DispatcherPriority.Input, new DispatcherOperationCallback( delegate(object unused) { if (!IsCanceledOrShuttingDown) { _applicationRunner = new DocObjHost.ApplicationRunner(ExecuteDownloadedApplication); _runApplication = true; Shutdown(); // The Application.Exit event handler will continue... } return null; }), null); return null; }
private object DoDirectActivation(object unused) { if (IsCanceledOrShuttingDown) return null; try { // Verify that this app is actually cached. This is because the call to // CreatePartialActivationContext can succeed when we don't want it to; // it appears to be insensitive to some parts of the ApplicationIdentity, // or it tries to make things work when they really should fail. Looking // at the UserApplicationTrusts does a better comparison. if (ApplicationSecurityManager.UserApplicationTrusts[_identity.ToString()] != null) { _context = System.ActivationContext.CreatePartialActivationContext(_identity); _applicationRunner = new DocObjHost.ApplicationRunner(ExecuteDirectApplication); _runApplication = true; this.Shutdown(); } else { TryUriActivation(); } } catch(Exception exception) { // Delete the cached trust decision to force going down the full ClickOnce path next time DeleteCachedApplicationTrust(_identity); // Fatal error like NullReferenceException and SEHException should not be ignored. if (exception is NullReferenceException || exception is SEHException) { throw; } else { TryUriActivation(); } } return null; }