When your application has terminated it can be only restarted by some kind of watcher.
The simplest solution would be using a batch / command file that re-starts the application when it returns specific codes. For example return zero from your main function and call
Environment.Exit Method (Int32) (System)[
^] with an exception specific value from within exception handlers that terminate the application (it might be also necessary to provide a handler for unhandled exceptions).
The command file might look like:
@ECHO OFF
:Restart
myapp.exe
IF %ERRORLEVEL% NEQ 0 GOTO Restart
This will restart myapp.exe when it returns non zero.
Testing the
ERRORLEVEL
variable can be used to check for different codes. To check only for zero the command file might be simpler:
@ECHO OFF
:Restart
myapp.exe || GOTO Restart