0

I would like to know how i can exit my application using MVVM

I have tried App.Current.Shutdown(); but I have the folowing output : MyProgram has stop working

Could you please help me ?

Fabien Papet
  • 2,244
  • 2
  • 25
  • 52

2 Answers2

1

You are using the correct method, however depending upon which mode you have your ShutDownMode set to, you'll need to make sure that either your Main Window is closed, or if you have it set to OnLastWindowClosed, then all your windows must be closed prior to shutting down your application.

This answer explains the detail a little bit more;

https://stackoverflow.com/a/2820377/1305169

Community
  • 1
  • 1
PGallagher
  • 3,123
  • 2
  • 26
  • 37
1

The view model that your main window sees needs to publish an event using your chosen mechanism. The main window should listen for this event and close when it sees it.

It is important that you also send a message to other areas of the system to notify of the shutdown. This way you can ensure that non-daemon threads are shutdown and that all unmanaged handles are closed. For any filestreams you may have open, this is the appropriate opportunity to flush your stream!

Gusdor
  • 14,001
  • 2
  • 52
  • 64