C# process restart loop

Posted by Andrej on Stack Overflow See other posts from Stack Overflow or by Andrej
Published on 2010-03-18T00:00:19Z Indexed on 2010/03/18 0:01 UTC
Read the original article Hit count: 886

Filed under:
|
|

Hi,

I'm trying to make a console app that would monitor some process and restart it if it exits. So, the console app is always on, it's only job is to restart some other process.

I posted my code below.. it basically works but just for one process restart...

I would appriciate any help!!

Thanks in advance!

                    {
        System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName(SOME_PROCESS);
        p[0].Exited += new EventHandler(Startup_Exited);

            while (!p[0].HasExited)
            {
                p[0].WaitForExit();
            }

        //Application.Run();
    }

    private static void Startup_Exited(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start(AGAIN_THAT_SAME_PROCESS);  
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about process