0

I am searching for a nice way how to close an WinRT app after fatal error.

This should be used only in last chance error handlers TaskScheduler.UnobserveTaskExcption and App.UnhandledException where I obviously failed to handle it correctly on right places. Should never happen, but...

Desired behaviour: Application should then show 'Sorry' message, log the exception and after user clicks Ok button, app should be closed.

I searched for solutions and lot of results points me, that WinRT must not be closed programmatically. Eg. here programatically close win8 app . When I call Exit method, app is closed, but afterwards exceptions are thrown, like could not do this and that because app is closing...etc.. Makes me kind of nervous.

How would you solve my problem? It has no sence to keep the app running after unhandled exception, and let it crash by setting Handled = false is not good solution as well I thing. Beside this UnobservedExceptions does not trigger crash. I heard that apps with crashes will be removed from store.

Thx for your ideas!

Community
  • 1
  • 1
Lukas K
  • 6,037
  • 4
  • 23
  • 31

2 Answers2

2

Referring to the application lifecycle provided by Microsoft, the app should terminate without any warning and return the user to the Start screen.

http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx#app_crash

Patrick E
  • 36
  • 3
0

You should not be closing apps which target the Windows Runtime at all. The app lifecycle management system built-in takes into account many factors including usage statistics and current system resources and will almost certainly make better decisions about when to close apps than you will.

  • I know about this problem. But what should I do, when there is some fatal exception thrown? That is not really good idea to let the app continue in some corrupted state... Of course I try to avoid this state firstly, but in case it happens? – Lukas K Aug 13 '13 at 20:48
  • It would also be supremely helpful when porting test cases to run on WinRT to be able to programatically kill them when they complete, for automation purposes. Not all programs targeting WinRT are intended for production use. Luckily there are a few options in http://stackoverflow.com/questions/9028373 – chrisvarnz Oct 03 '14 at 08:44