Reputation: 2200
I have a WPF application with a GUI on the MainWindow. I want to dispose this window after a while based on some user actions. But I want the application continue to run in background. I know that Window can be set to hidden, but it still uses the memory.How to destroy the MainWindow without quitting the WPF application? Also I would like to know if it is possible to relaunch the MainWindow after it was disposed.
Upvotes: 0
Views: 1109
Reputation: 613
this.Close(); //Will close the window but keep the application running.
var mw = new MainWindow();
mw.Show(); //Will open a new MainWindow and show it.
mw.Close(); //Close this one too.
That said hiding it is the best choice, the amount of memory it uses should really be irrelevant. That's what memory is there for.
Upvotes: 1