我的申请有问题。我在App.xaml中选择了Loadscreen.xaml作为“StartupUri”。 Loadscreen.xaml.cs包含一个进度条,它运行到100% - 比它关闭并打开MainWindow。问题是,它在关闭Loadscreen后打开MainWindow两次。我的谬误是什么?
的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();
}
}
答案 0 :(得分:5)
您正在打开Loadscreen
的两个实例:
StartupUri="Loadscreen.xaml"
Application_Startup
中因Startup="Application_Startup"
而被调用的另一个。摆脱StartupUri="Loadscreen.xaml"
,问题应该消失。