我有以下代码,但为什么从未调用过 ProcessExited
方法?如果我不使用 Windows shell (startInfo.UseShellExecute = false
),也是一样的。
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = path;
startInfo.Arguments = rawDataFileName;
startInfo.WorkingDirectory = Util.GetParentDirectory(path, 1);
try
{
Process correctionProcess = Process.Start(startInfo);
correctionProcess.Exited += new EventHandler(ProcessExited);
correctionProcess.WaitForExit();
status = true;
}
.....
internal void ProcessExited(object sender, System.EventArgs e)
{
//print out here
}
最佳答案
为了在 Exited
事件上接收回调,EnableRaisingEvents
必须设置为 true。
Process correctionProcess = Process.Start(startInfo);
correctionProcess.EnableRaisingEvents = true;
correctionProcess.Exited += new EventHandler(ProcessExited);
关于c# - 为什么我的进程的 Exited 方法没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4504170/