views:

81

answers:

2

Have you used the Application Recovery APIs with vista?

http://msdn.microsoft.com/en-us/library/aa373347(VS.85).aspx

Do you find them to be reliable and easy to work with?

I am reading through some of the docs and it seems rolling my own might be a better way to go because I can make my solution compatible with XP. Has anyone taken a stab at writing their own? Is there anything that the native methods can offer that cannot easily be reproduced by hand? What are some potential approaches for writing this type of solution, I feel that I may need a background service running to monitor the health of my application, is this the only way?

A: 

The only way is to have a service monitoring the application.

The reason being that if the application has a truly fatal error that the app itself can't handle, then something outside of it has to perform the recovery operation.

The background service can use WMI (works on XP, Vista, etc) to monitor the application. When it starts, how much memory it is using, when it closes down, etc.

Chris Lively
+1  A: 

It would be helpful if you describe why you need to monitor it.

Is it running unattended without a GUI? Then you might create a Windows Service instead. There are restart options for Services already in XP.

Is it a GUI app, that provides some background services even if the user is away? Consider separating it into a Windows Service (that needs to run all the time), and a GUI app, which can crash without affecting the service operation.

Or are you writing a "kiosk" app that can't rely on a user to restart it?

You could write a small "wrapper" application that simply launches your real application and waits for it to exit. When it exits, examine e.g. the exit code to decide whether it crashed or exited regularly.

To monitor application hangs, have your real application "Ping" the wrapper in regular intervals (using a timer). If the wrapper doesn't receive a ping for a certain amount of time, it can kill and restart the real application.

Since the wrapper is small, the risk that it crashes as well is low. But if this is an issue for you, the real app could probably monitor the wrapper in reverse.

oefe