Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart an Application on Crash

Tags:

.net

I need to restart my application if an unhandled exception occurs. I'd like to mimic Office applications like Word or even Visual Studio which, when an application crashes or hangs (stops responding), shows a pop-up and asks the user whether he'd like to restart the app or kill it.

I'm not sure how it's done since it's possible that my app has completely and utterly crashes (as explained here). Right now I thinking some form of Watchdog or Launcher app, but my gut tells me that this isn't the way the applications I mentioned do it.

So any light on the "best" or "mostly accepted" way of doing it would be greatly appreciated.

As always, thanks all for the attention.

like image 822
Bruno Brant Avatar asked Apr 27 '12 18:04

Bruno Brant


1 Answers

You could use Windows Error Reporting (WER) to register the application for restart (and even recovery) when it has been running for at least 60 seconds before the unhandled exception occurs.

I haven't tried it, but I've found the following links describing how to do it:

  • http://msdn.microsoft.com/en-us/library/windows/desktop/bb525423(v=vs.85).aspx
  • http://channel9.msdn.com/posts/Application-Restart-and-Recovery-on-Windows-7-in-Native-Code
  • http://code.msdn.microsoft.com/Windows-Restart-and-cc461aa9 (also contains C# sample)

Unfortunately this only seems to work in Windows 7 and above.

like image 133
Xharze Avatar answered Oct 14 '22 15:10

Xharze