private void ExitGame(object sender, RoutedEventArgs e) { soundEngine.ForceStopAllPlayers(); var window = Window.GetWindow(this); window.IsVisibleChanged -= CleaningAfterPageClosedHandler; System.Windows.Application.Current.Shutdown(); //close the application }