/// <summary> /// Make sure we startup everything after WPF instantiated /// </summary> /// <param name="e">StartupEventArgs</param> protected override async void OnStartup(StartupEventArgs e) { Log.Debug().WriteLine("Starting application startup"); _bootstrapper.Configure(); // Register the UI SynchronizationContext, this can be retrieved by specifying the name "ui" for the argument _bootstrapper.Builder.RegisterInstance(SynchronizationContext.Current).Named <SynchronizationContext>("ui"); _bootstrapper.Builder.RegisterInstance(TaskScheduler.FromCurrentSynchronizationContext()).Named <TaskScheduler>("ui"); // The following makes sure that Caliburn.Micro is correctly initialized on the right thread and Execute.OnUIThread works // Very important to do this, after all assemblies are loaded! _caliburnMicroBootstrapper = new CaliburnMicroBootstrapper(_bootstrapper); _bootstrapper.Builder.RegisterInstance(_caliburnMicroBootstrapper).As <IService>().SingleInstance(); // Prepare the bootstrapper await _bootstrapper.InitializeAsync().ConfigureAwait(true); _caliburnMicroBootstrapper.Initialize(); // Now check if there is a lock, if so we invoke OnAlreadyRunning and return if (_bootstrapper.IsAlreadyRunning) { var exitCode = OnAlreadyRunning?.Invoke() ?? -1; Shutdown(exitCode); return; } // Start Dapplo, services which need a UI context need to configure this await _bootstrapper.StartupAsync().ConfigureAwait(true); Log.Debug().WriteLine("Finished application startup"); // This also triggers the Caliburn.Micro.BootstrapperBase.OnStartup base.OnStartup(e); }
/// <summary> /// Make sure we startup everything after WPF instanciated /// </summary> /// <param name="e">StartupEventArgs</param> protected override async void OnStartup(StartupEventArgs e) { // Enable UI access for different Dapplo packages, especially the UiContext.RunOn // This only works here, not before the Application is started and not later UiContext.Initialize(); _bootstrapper.Configure(); // Register the UI SynchronizationContext, this can be retrieved by specifying the name "ui" for the argument _bootstrapper.Builder.RegisterInstance(SynchronizationContext.Current).Named <SynchronizationContext>("ui"); _bootstrapper.Builder.RegisterInstance(TaskScheduler.FromCurrentSynchronizationContext()).Named <TaskScheduler>("ui"); // Prepare the bootstrapper await _bootstrapper.InitializeAsync().ConfigureAwait(true); // The following makes sure that Caliburn.Micro is correctly initialized on the right thread and Execute.OnUIThread works // Very important to do this, after all assemblies are loaded! _caliburnMicroBootstrapper = new CaliburnMicroBootstrapper(_bootstrapper); _caliburnMicroBootstrapper.Initialize(); // Now check if there is a lock, if so we invoke OnAlreadyRunning and return if (_bootstrapper.IsAlreadyRunning) { var exitCode = OnAlreadyRunning?.Invoke() ?? -1; Shutdown(exitCode); return; } // Start Dapplo, do not use configure-await false here, so the OnStartup doesn't have any issues await _bootstrapper.StartupAsync().ConfigureAwait(true); // This also triggers the Caliburn.Micro.BootstrapperBase.OnStartup base.OnStartup(e); }