MainWindow opens twice (StartupUri, App, Loadscreen)

c#, mainwindow, xaml

Solution

You're opening two instances of `Loadscreen`:

- One with `StartupUri="Loadscreen.xaml"`

- The other one from `Application_Startup` which is called because of `Startup="Application_Startup"`.

Just get rid of `StartupUri="Loadscreen.xaml"` and the problem should be gone.

Problem

I've got a problem with my application. I selected my Loadscreen.xaml as the "StartupUri" in my App.xaml. The Loadscreen.xaml.cs contains a progressbar, that runs until 100% - than it closes and opens the MainWindow. The problem is, that it opens the MainWindow twice after closing the Loadscreen. What is my fallacy? App.xaml: ``` StartupUri="Loadscreen.xaml" Startup="Application_Startup"> ``` Loadscreen.xaml.cs: ``` public void Timer_Tick(object sender, EventArgs e) { progressBar_Ladebalken.Value = i; label_Titel.Content = i + "%"; Mouse.OverrideCursor = Cursors.Wait; if (i < 100) { i += 1; } else { i = 0; Mouse.OverrideCursor = null; Timer.Stop(); Window W = new MainWindow(); W.Show(); this.Close(); } ``` public void Application_Startup: ``` public void Application_Startup(object sender, StartupEventArgs e) { bool Absicherung; Mutex Mutex = new Mutex(true, this.GetType().GUID.ToString(), out Absicherung); if (Absicherung) { Window W = new Loadscreen(); W.Closed += (sender2, args) => Mutex.Close(); ; W.Show(); } else { MessageBox.Show(FM_Mutex_Meldung, FM_Mutex_Titelleiste, MessageBoxButton.OK, MessageBoxImage.Information); Mutex.Close(); Application.Current.Shutdown(); } } ```

Original source