为什么流程的退出方法不被调用?

时间:2022-04-15 01:41:22

I have following code, but why is the ProcessExited method never called? It is the same if I don't a use Windows shell (startInfo.UseShellExecute = false).

我有以下代码,但是为什么processexable方法从未被调用?如果我不使用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
}

4 个解决方案

#1


180  

In order to receive a callback on Exited event, the EnableRaisingEvents must be set to true.

为了接收退出事件的回调,必须将EnableRaisingEvents设置为true。

Process correctionProcess = Process.Start(startInfo);
correctionProcess.EnableRaisingEvents = true;
correctionProcess.Exited += new EventHandler(ProcessExited); 

#2


25  

From MSDN:

从MSDN:

The Exited event indicates that the associated process exited. This occurrence means either that the process terminated (aborted) or successfully closed. This event can occur only if the value of the EnableRaisingEvents property is true.

退出事件指示关联的进程退出。此事件意味着进程终止(中止)或成功关闭。只有当EnableRaisingEvents属性的值为true时,才会发生此事件。

Have you set that property to true?

你把那个属性设置为真了吗?

#3


13  

You must set Process.EnableRaisingEvents to true.

必须设置过程。EnableRaisingEvents为true。

#4


11  

Set correctionProcess.EnableRaisingEvents = true

设置correctionProcess。EnableRaisingEvents = true

#1


180  

In order to receive a callback on Exited event, the EnableRaisingEvents must be set to true.

为了接收退出事件的回调,必须将EnableRaisingEvents设置为true。

Process correctionProcess = Process.Start(startInfo);
correctionProcess.EnableRaisingEvents = true;
correctionProcess.Exited += new EventHandler(ProcessExited); 

#2


25  

From MSDN:

从MSDN:

The Exited event indicates that the associated process exited. This occurrence means either that the process terminated (aborted) or successfully closed. This event can occur only if the value of the EnableRaisingEvents property is true.

退出事件指示关联的进程退出。此事件意味着进程终止(中止)或成功关闭。只有当EnableRaisingEvents属性的值为true时,才会发生此事件。

Have you set that property to true?

你把那个属性设置为真了吗?

#3


13  

You must set Process.EnableRaisingEvents to true.

必须设置过程。EnableRaisingEvents为true。

#4


11  

Set correctionProcess.EnableRaisingEvents = true

设置correctionProcess。EnableRaisingEvents = true