我有以下code,但为什么 ProcessExited
方法不会被调用?这是相同的,如果我不使用Windows外壳程序( startInfo.UseShellExecute = FALSE
)。
的ProcessStartInfo的StartInfo =新的ProcessStartInfo();
startInfo.CreateNoWindow = TRUE;
startInfo.UseShellExecute =真;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName =路径;
startInfo.Arguments = rawDataFileName;
startInfo.WorkingDirectory = Util.GetParentDirectory(路径,1);
尝试
{
流程correctionProcess =的Process.Start(StartInfo的);
correctionProcess.Exited + =新的EventHandler(ProcessExited);
correctionProcess.WaitForExit();
状态= TRUE;
}
......
内部空隙ProcessExited(对象发件人,发送System.EventArgs)
{
//打印出在这里
}
解决方案
为了收到关于已退出回调
情况下,EnableRaisingEvents必须设置为真。
过程correctionProcess =的Process.Start(StartInfo的);
correctionProcess.EnableRaisingEvents = TRUE;
correctionProcess.Exited + =新的EventHandler(ProcessExited);
I have following code, but why the ProcessExited
method is never called? It is the same if I don't use 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
}
解决方案
In order to receive a callback on Exited
event, the EnableRaisingEvents
must be set to true.
Process correctionProcess = Process.Start(startInfo);
correctionProcess.EnableRaisingEvents = true;
correctionProcess.Exited += new EventHandler(ProcessExited);