-2

So, I'm writing a program, here's the start of it!

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.Process.Start(@"C:\\Windows\\ehome\\ehshell.exe");
            System.Diagnostics.Process.Start(@"E:\\Xpadder\\WMC.xpaddercontroller");
        }
    }
}

All it does is open the two files. What I want it to do is also wait until it detects when ehshell.exe stops running and then force another program (in this case xpadder) to end as well.

I've had a look for code for doing this, but I'm not the best at C# and not 100% sure what I'm looking for!

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

1
        var p1 = new ProcessStartInfo
        {
            FileName = atomicParsleyFile,
            Arguments = atomicParsleyCommands,
            WindowStyle = ProcessWindowStyle.Hidden,
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardOutput = true
        };

        var proc = new Process { StartInfo = p1 };

        if (!proc.Start())
        {
            throw new ApplicationException("Starting atomic parsley failed!");
        }

                    /*Repeat above for second process here */

        Console.WriteLine(proc.StandardOutput.ReadToEnd());

        proc.WaitForExit(); //Run AtomicParsley and Wait for Exit
                    proc2.Kill();
Robert McKee
  • 21,305
  • 1
  • 43
  • 57
  • It could probably be shorter, but I ripped it out of something I did a while ago, and I needed the above options the way they were. If you expect your program to output a lot of data, you should either not redirect the standard output, or read and output in smaller chunks than I did. – Robert McKee Aug 24 '13 at 01:48
0
    static void Main(string[] args)
    {
        System.Diagnostics.Process p1 = System.Diagnostics.Process.Start(@"C:\\Windows\\ehome\\ehshell.exe");
        System.Diagnostics.Process p2 = System.Diagnostics.Process.Start(@"E:\\Xpadder\\WMC.xpaddercontroller");
        p1.Exited += (s,e) => {
           if(!p2.HasExited) p2.Kill();
        };

    }
King King
  • 61,710
  • 16
  • 105
  • 130