Restart application on unhandled exception

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

    I've done this before in Windows by running said program from another program via a win32 CreateProcess call. The other program then waits on the "monitored" process to exit, and calls its CreateProcess() again if it does. You wait for a process to exit by performing a WaitForSingleObject on the process' handle, which you get as one of the return values from your CreateProcess() call.

    You will of course want to program in some way to make the monitoring process shut itself and its child process down.

提交回复
热议问题