0

I have written code to swap configs in a windows 8 app. This needs an immediate restart of the app.

Here's what I've tried:

1) Close the application. Apparently this is forbidden by Microsoft.

2) Accepts the user's config change, then add it to Tasks to be done when the app is next closed. Using something like the Application.Exit Event in WPF, but that is missing in here. I can see OnSuspending, but that isn't sufficient because the application may be resumed with the current memory intact.

3) Restart the application. Still looking in to this one. I suspect I'd have to be quite clever about this not violate Microsoft rules like this related question

Here's what I've not tried: Hotswapping (This is dev effort and bug risk and really just isn't worth it), Locking the UI and compelling the user to close (just no) etc etc. ... Also asking nicely, I've not tried that.

I think 2 is the most likely option

- How can I schedule and run code on the closing of my application?

Community
  • 1
  • 1
Nathan Cooper
  • 6,262
  • 4
  • 36
  • 75
  • What sort of configs are you trying to change? Why does this need a restart? In most cases configuration changes should be made live without needing a restart. There is no way for a Windows Store app to restart itself. Programmatically closing an app is generally user-unfriendly and should be avoided, but is not forbidden by the certification requirements – Rob Caplan - MSFT Oct 31 '14 at 21:42
  • I gave up and implemented hot-swapping of files. It all ended up working quite nicely. – Nathan Cooper Nov 25 '14 at 12:58

1 Answers1

0

Restarting a Windows app is not possible as far as I know. I had a similar issue when I needed to restart my app in order to switch themes (dark or light). I ended up displaying a message to the end user indicating a restart was needed to apply the new setting. I have seen other people closing an app simply by throwing an exception, it works for the closing part but isn't very elegant.

Niels
  • 1,366
  • 15
  • 21
  • 1
    Written properly you shouldn't need to restart to switch themes in Windows 8.1 (it was trickier in Windows 8, but still not strictly necessary). Application.Exit is a cleaner way to exit the app than throwing an exception. – Rob Caplan - MSFT Oct 31 '14 at 21:45
  • App.Current.Exit(); works to exit the app. We do this for QA testing after the tester resets the environment the App is pointing to. Before the app exits, settings are saved to isolated storage, and picked up when the tester restarts the app. We don't allow this for end-users, but it is convenient for testing so as to ensure we have a clean Session state. – ezaspi Mar 14 '16 at 20:58
  • As @RobCaplan-MSFT says It's not needed to restart the app for theme changes - I have this working fine. You just need to use {ThemeResource key} instead of {StaticResource key} to get changes flushed through to your styles immediately instead of needing a restart. – MemeDeveloper Apr 03 '16 at 16:25