コード例 #1
0
        protected override void OnStartup(StartupEventArgs args)
        {
            using (Duration.Measure(Logger, "OnStartup - " + GetType().Name))
            {
                Logger.Info("Starting");

                // ReSharper disable once RedundantToStringCallForValueType
                var dispatcherMessage =
                    $"Dispatcher managed thread identifier = {Thread.CurrentThread.ManagedThreadId.ToString()}";

                Logger.Info(dispatcherMessage);
                Debug.WriteLine(dispatcherMessage);

                Logger.Info($"WPF rendering capability (tier) = {(RenderCapability.Tier / 0x10000).ToString()}");
                RenderCapability.TierChanged += (s, a) =>
                                                Logger.Info($"WPF rendering capability (tier) = {(RenderCapability.Tier / 0x10000).ToString()}");

                base.OnStartup(args);

                BootStrapper.Start();

                var schedulerService = BootStrapper.Resolve <ISchedulerService>();
                var messageService   = BootStrapper.Resolve <IMessageService>();
                var gestureService   = BootStrapper.Resolve <IGestureService>();

                ObservableExtensions.GestureService = gestureService;

                // Load the application settings asynchronously
                LoadSettingsAsync(schedulerService)
                .Wait();

                var window = new MainWindow(messageService, schedulerService);

                // The window has to be created before the root visual - all to do with the idling service initialising correctly...
                window.DataContext = BootStrapper.RootVisual;

                window.Closed += HandleClosed;
                Current.Exit  += HandleExit;

                // Let's go...
                window.Show();


                if (Logger.IsInfoEnabled)
                {
                    // Monitoring heartbeat only when info level is enabled...
                    ObserveHeartbeat(schedulerService)
                    .DisposeWith(_disposable);
                }

#if DEBUG
                ObserveUiFreeze()
                .DisposeWith(_disposable);
#endif
                ObserveCultureChanges()
                .DisposeWith(_disposable);

                Logger.Info("Started");
            }
        }