private void SecondWindowClosing(object sender, System.ComponentModel.CancelEventArgs e) { StartSimulationButton.IsEnabled = true; Simulation.Closing -= SecondWindowClosing; Simulation.Dispose(); Simulation = null; GC.Collect(); }
private void StartSimulation(object sender, RoutedEventArgs e) { if (StartSimulationButton.IsEnabled) { try { Simulation = new SimulationWindow(); StartSimulationButton.IsEnabled = false; Simulation.Show(); Simulation.Closing += SecondWindowClosing; } catch (Exception ex) when(ex is MapLoadingException || ex is FormatException) { MessageBox.Show($"Nie można uruchomić symulacji, ponieważ nie udało się wczytać mapy.", "Błąd", MessageBoxButton.OK); } } }