Restart application on unhandled exception

前端 未结 5 1488
天涯浪人
天涯浪人 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:16

    Let Windows be your watchdog. You can call ChangeServiceConfig2 to set the failure actions for your service. (If your server isn't a service, then you're doing it wrong.) Specify SERVICE_CONFIG_FAILURE_ACTIONS for the dwInfoLevel parameter, and in the SERVICE_FAILURE_ACTIONS structure, set lpsaActions to an array of one or more SC_ACTION values. The type you want is SC_ACTION_RESTART.

提交回复
热议问题