I run a child process through my program. After a while, he will complete. I need to catch this moment. Of course, I can parse all the running processes and see when the desired process is not in the list, but who can tell me a more elegant solution?

  • You can wrap this process with your wrapper, which will simply call the required method, the handler at the end of the process. - Dmitry Polyanin

1 answer 1

Turn on the notification at the end of the process and subscribe to Exited :

 public void StartProcess(string fileName) { Process process = new Process(); process.StartInfo.FileName = fileName; process.EnableRaisingEvents = true; process.Exited += (sender, e) => { Console.WriteLine($"Процесс завершен с кодом {process.ExitCode}"); } process.Start(); } 
  • does not work ( Process proc = new Process(); proc.StartInfo.FileName = "wevtutil"; proc.StartInfo.Arguments = " qe System /c:100 /rd:true /f:text > Security.log"; proc.Exited += (sender, e) => { Console.WriteLine($"Процесс завершен с кодом {proc.ExitCode}"); }; proc.Start(); Console.ReadKey(); - polsok
  • one
    @polsok And where are you proc.EnableRaisingEvents = true delhi?) - Ares
  • And now it works thanks - polsok