// Initialize everything on the UI thread, and report+die for any problems or SwitchContext from SplashForm to EDDiscoveryForm. private void MainEngineStart(object sender, EventArgs e) { var tim = (Timer)sender; tim?.Stop(); var launchArg = ((EDDFormLaunchArgs)tim?.Tag)?.Clone() ?? new EDDFormLaunchArgs(); tim?.Dispose(); try { EDDMainForm = new EDDiscoveryForm(); SetLoadingMsg("Checking Ship Systems"); EDDiscoveryController.Initialize(SetLoadingMsg); // this loads up the options EDDOptions.Instance.NoWindowReposition |= launchArg.PositionReset; EDDOptions.Instance.NoTheme |= launchArg.ThemeReset; EDDMainForm.Init(SetLoadingMsg); // call the init function, which will initialize the eddiscovery form SetLoadingMsg("Establishing Telepresence"); SwitchContext(EDDMainForm); // Ignition, and liftoff! } catch (Exception ex) { // There's so many ways that things could go wrong during init; let's fail for everything! EDDMainForm?.Dispose(); FatalExceptionForm.ShowAndDie(MainForm, "Initializing", Properties.Resources.URLProjectFeedback, ex); } }
// event handlers // Initialize everything on the UI thread soon after the `Application` has been `.Run()`, and transfer context (MainForm) from the SplashForm to the EDDiscoveryForm. private void initTimer_Tick(object sender, EventArgs e) { ((Timer)sender)?.Stop(); ((Timer)sender)?.Dispose(); try { EDDMainForm = new EDDiscoveryForm(); SetLoadingMsg("Checking Ship Systems"); EDDiscoveryController.Initialize(Control.ModifierKeys.HasFlag(Keys.Shift), Control.ModifierKeys.HasFlag(Keys.Control), SetLoadingMsg); EDDMainForm.Init(SetLoadingMsg); // call the init function, which will initialize the eddiscovery form SetLoadingMsg("Establishing Telepresence"); EDDMainForm.Show(); } catch (Exception ex) { // There's so many ways that things could go wrong during init; let's fail for everything! EDDMainForm?.Dispose(); FatalExceptionForm.ShowAndDie(MainForm, "Initializing", Properties.Resources.URLProjectFeedback, ex); } var splashForm = MainForm; MainForm = EDDMainForm; // Switch context splashForm.Close(); // and cleanup }