-2

所以,我正在编写一个程序,这就是它的开始!

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

它所做的只是打开这两个文件。我想要它做的也是等到它检测到 ehshell.exe 何时停止运行,然后强制另一个程序(在本例中为 xpadder)也结束。

我已经查找了执行此操作的代码,但我不是 C# 方面的佼佼者,也不是 100% 确定我在寻找什么!

4

2 回答 2

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();
于 2013-08-24T01:39:30.920 回答
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();
        };

    }
于 2013-08-24T06:55:16.900 回答