Restart application on unhandled exception

前端 未结 5 1487
天涯浪人
天涯浪人 2021-01-18 15:20

Is it possible to have a program restart automatically if it crashes?

Something like:

  1. An unhandled exception is thrown.
  2. Release all resources
5条回答
  •  深忆病人
    2021-01-18 16:13

    I did something similar by implementing a watchdog. The watchdog ran as a service and would wait for a ping (called petting the dog) from the monitored process. If the monitored process died due to an exception, watchdog would cleanup and relaunch the application.

    In case the application was not responding(no ping in a certain time) the watchdog would kill it and then restart it.

    Here is a link to an implementation that you might want to use: http://www.codeproject.com/KB/security/WatchDog.aspx

    (PS: I implemented my own version but I cannot post it here. I found this from a quick google search and have no first hand experience with this particular implementation.)

提交回复
热议问题