为什么处理的已退出方法不会被调用? [英] why Process's Exited method not being called?
本文介绍了为什么处理的已退出方法不会被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下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)
{
//打印出在这里
}
解决方案
为了收到关于已退出回调
情况下,<一个href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.enableraisingevents.aspx"><$c$c>EnableRaisingEvents$c$c>必须设置为真。
过程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);
这篇关于为什么处理的已退出方法不会被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文