How to receive a message that an application has crashed?


I am working on an application that changes some settings in the disk manager after it launches. It undoes all those changes when it is closed properly.

However when the application crashes because of some reason, it can't undo the changes it did. I am planning to write some sort of a service, which waits for a notification that the application has crashed, and undoes all the changes done by the application.

Is there anyway for one application or a process to be informed when another application crashes? I mean is there any sort of event or message that windows throws for this case?
Who is Participating?
One simple option might be to wrap your application in another application.
For example, create a class called, for example, MainApplication. Give it a method called Run that takes no parameters and returns no values, eg:
void MainApplication::Run()

transfer all the functionality of your existing program to this class, and all the code from your main() function to the Run() method.
Now create a wrapper program, I will call it TestHarness.
In the main function create an instance of your class inside a try-catch block and call the run method.
If it crashes it should raise an exception which your harness program can capture. You will then know immediately if iit has crashed.
You can then perform whatever cleanup stuff you need to.
you might want to look at Servers Alive application.  It can carry out actions off the back of a failure.
Write it as a service and have your service installer specify the Recovery option of running another application on the first failure.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.