How to programmatically close the app?

Topics: Prism v2 - WPF 4
Apr 25, 2011 at 3:08 PM

I need to close the app from the Shell at the startup time when the security validation is failed. Where is the recommended place to validate the security, e.g., App, or Bootstrapped? Any how to close the App?

Thanks in advance.

Developer
Apr 25, 2011 at 4:16 PM

Hi,

If you have the ShutdownMode set to OnLastWindowClose (which is the default value), you need to call your main window's Close method in order to close the application. You could have your Shell subscribe to an event through the event aggregator, so that it calls its Close method when that event is published.

The general recommended practice would be to place the responsibility of carrying out the validation on a component placed on a module, and load other modules based on the result of that validation. However, the decision of where to place it depends mostly on the specific conditions of your security validation.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Apr 25, 2011 at 6:24 PM

Hi Guido,

Thanks for your response and suggestion. I am using Infragistics toolkit and it seems it does not work with OnLastWindowClose. If I set to OnExplicitShutdown, how can I programmatically shut down the app? Thanks in advance.

Developer
Apr 25, 2011 at 7:08 PM
Edited Apr 25, 2011 at 7:08 PM

In case it is set to OnExplicitShutdown, you need to call the Application.Shutdown method explicitly in order for the application to shut down.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi