Why does my C# WPF program keep executing lines after Application.Shutdown()? Why does my C# WPF program keep executing lines after Application.Shutdown()? wpf wpf

Why does my C# WPF program keep executing lines after Application.Shutdown()?


Shutdown stops the Dispatcher processing, and closes the application as far as WPF is concerned, but doesn't actually kill the current thread.

In your case, you need to prevent code beyond that call from running. A simple return will suffice:

 if (chooser.ShowDialog() == false) {     Application.Current.Shutdown(0);     return; } else { //...


It doesn't Terminate your process instantly, its a controlled shutdown.

if you want ( not recommended ) to kill instantly

Process.GetCurrentProcess().Kill();