tags:

views:

74

answers:

1

Hi Everyone

I'm working on a WPF application which should be utilizable with two monitors. In the main window is a button which detaches a part of the content in a second window wich can then be used on the other minitor. That second window I implemented as a singleton. That works quite good except that the second window doesn't get destoryed on application shutdown which means that the app keeps running in the background.

Regarding that problem I'd like to know if a singleton is the right way to do this and if not what would be the right way. If it is, how do I get rid of the instance and why can't I access the singleton instance from app.xaml.cs?

Thanks for your help.

+3  A: 

This has nothing to do with your window being a singleton, it is related to the ShutdownMode property of your application. By default, its value is OnLastWindowClose, which means that the application will shut down when all windows are closed. So, you have to either manually close all your windows, or set the ShutdownMode to OnMainWindowClose. You can also call Application.Shutdown explicitly.

Thomas Levesque
Thanks a lot, ShutdownMode did the trick.
Anonymous Coward