private void OnResetButtonClick(object sender, RoutedEventArgs e) { //Makes a new thread and loads the loadingwindow, and starts the animation. Thread thread = new Thread(() => { if (_loadingWindow == null) { _loadingWindow = new LoadingWindow(); } _loadingWindow.StartAnimation(); System.Windows.Threading.Dispatcher.Run(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); UserInterface.ResetButtonClicked = true; ChangeSimulationControlsOnEnd(); UserInterface.IsSimulationPaused = false; PauseSimulationButton.Content = "Pause"; UserInterface.HasSimulationEnded = true; OnStopLoadingWindow?.Invoke(this, null); }