gpt4 book ai didi

c# - 为什么我的进程的 Exited 方法没有被调用?

转载 作者:IT王子 更新时间:2023-10-29 03:37:37 27 4
gpt4 key购买 nike

我有以下代码,但为什么从未调用过 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com