我有一个控制台应用程序和 Main 方法。我启动了一个类似下面代码的进程,当进程存在时,进程的 Exist 事件被触发,但它也关闭了我的控制台应用程序,我只想启动一个进程,然后在该进程的退出事件中启动另一个进程。
进程输出也反射(reflect)在我的主控制台应用程序中。
Process newCrawler = new Process();
newCrawler.StartInfo = new ProcessStartInfo();
newCrawler.StartInfo.FileName = configSection.CrawlerPath;
newCrawler.EnableRaisingEvents = true;
newCrawler.Exited += new EventHandler(newCrawler_Exited);
newCrawler.StartInfo.Arguments = "someArg";
newCrawler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
newCrawler.StartInfo.UseShellExecute = false;
newCrawler.Start();
最佳答案
您必须调用 newCrawler.WaitForExit()
才能一直保持到子进程完成。然后你可以使用 newCrawler.ExitCode
来获得退出值。
关于c# - 处理子进程的退出事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4689673/