What's the best way to watchdog a desktop application?

前端 未结 4 774
清歌不尽
清歌不尽 2020-12-01 05:39

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

4条回答
  •  生来不讨喜
    2020-12-01 06:18

    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!");
            }
        }
    }
    

提交回复
热议问题