Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Application still runs in background after closing

This is slightly related to the question asked here yet the answer does not apply to my case as I am not using threads:

WPF Not closing properly

I have converted one of my WinForm application to a WPF application, nothing drastic needed to be done except for change a few words to the WPF/C# 4.0 equivalents (MessageBoxButtons to MessageBoxButton, why the one letter difference?).

Anyway, if I run the application through the debugger it runs fine until I come to close it with the "X" button to the top right of the window. The application window closes but I noticed that the debugger still shows the stop icon, checking in the Task Manager confirms it is still running.

I am not running any other threads in the background so I know it's not waiting for something else.

I've only just started with WPF but I assumed that when the user closes the application then it should just...close?

Thanks for the help!

like image 853
Jamie Keeling Avatar asked Aug 22 '10 22:08

Jamie Keeling


People also ask

How do I close a WPF application?

We can close the window either by using "this. Close()"or by using "App. Current. Shutdown()".

Is WPF still relevant 2021?

WPF is still one of the most used app frameworks in use on Windows (right behind WinForms).

Is WPF being deprecated?

It was in 2006 that Windows Presentation Foundation (WPF) was released with . NET framework 3.0. Over the years it got improved and it is still now in the market in 2021.

How do I close all windows in WPF?

The proper way to shutdown a WPF app is to use Application. Current. Shutdown() . This will close all open Window s, raise some events so that cleanup code can be run, and it can't be canceled.


1 Answers

What is your shutdown mode? If it's explicit, then it's because you're not explicitly shutting down. If it's main window, it's because you've not assigned the main window to Application.MainWindow.

like image 65
Kent Boogaart Avatar answered Sep 28 '22 00:09

Kent Boogaart