Here you have several options.
The first (and best) is to add some type of global error handling that will catch any otherwise uncaught exceptions and handle them correctly. Along these lines, you should start adding the appropriate specific exception handling to your code base. Keep in mind that stack overflows and some security and memory exceptions will occur regardless of any global processing.
The second option is to have a monitoring service that simply checks if the current application is running. If this is not the case, then forcefully destroy the existing application and restart the new instance.
The third option is to separate your application from two applications. An external container-type application that simply runs another process. The container application will not have a user interface, but it will start the main process and look at it (as option 2 above). I saw that it is used in various "modular" applications.
The bottom line is that the only real way to do this is to have 2 applications: one for monitoring, the other for creating a user interface and everything else.
Notme
source share