开发者

C#: How to kill a singleton window

开发者 https://www.devze.com 2022-12-23 15:24 出处:网络
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 othe

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 win开发者_如何转开发dow 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号