I need some way to monitor a desktop application and restart it if it dies.
Initially I assumed the best way would be to monitor/restart the process from a Windows
The watchdog process could make use of System.Diagnostics.Process to launch the application, use the WaitForExitMethod() and check the ExitCode property.
In response to the complaints over the question, I have had to use such a method when working with a legacy call center application over which I had no source control access.
EDIT:
For the host application you could use a .NET application of output type "Windows Application" and simply not have a form at all. For example:
namespace WindowsFormsApplication1
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
var info = new ProcessStartInfo(@"calc.exe");
var process = Process.Start(info);
process.WaitForExit();
MessageBox.Show("Hello World!");
}
}
}