Exemplo n.º 1
0
        /// <summary>
        /// Starts up the application asynchronously.
        /// </summary>
        /// <returns></returns>
        private static async Task StartupAsync()
        {
            // Quits if another instance already exists
            if (!IsInstanceUnique)
            {
                return;
            }

            // Check if we are in DEBUG mode
            EveMonClient.CheckIsDebug();

            // Check if we are in SNAPSHOT mode
            EveMonClient.CheckIsSnapshot();

            // Subscribe application's events (especially the unhandled exceptions management for the crash box)
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.AssemblyResolve    += CurrentDomain_AssemblyResolve;
            Application.ThreadException += Application_ThreadException;
            Application.ApplicationExit += ApplicationExitCallback;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            // Find our files
            EveMonClient.InitializeFileSystemPaths();

            // Creates a trace file
            EveMonClient.StartTraceLogging();
            EveMonClient.Trace("Starting up", false);

            // Make our windows nice
            MakeWindowsJuicy();

            // Ensures the installation file downloaded through the autoupdate is correctly deleted
            UpdateManager.DeleteInstallationFiles();

            // Upgrades the Cloud Storage Service Provider settings
            CloudStorageServiceProvider.UpgradeSettings();

            // Initialization
            EveMonClient.Initialize();
            Settings.Initialize();

            // Did something requested an exit before we entered Run() ?
            if (s_exitRequested)
            {
                return;
            }

            try
            {
                // Fires the main window
                EveMonClient.Trace("Main loop - start", printMethod: false);
                s_mainWindow = new MainWindow();
                Application.Run(s_mainWindow);
                EveMonClient.Trace("Main loop - done", printMethod: false);

                // Save before we quit
                await Task.WhenAll(Settings.SaveImmediateAsync(), EveIDToName.SaveImmediateAsync());
            }
            finally
            {
                // Stop the one-second timer right now
                EveMonClient.Shutdown();
                EveMonClient.Trace("Closed", printMethod: false);
                EveMonClient.StopTraceLogging();
            }
        }