ProcessStartInfo.UseShellExecute = true 并等待进程退出

mos*_*ech 5 .net c# shellexecute

我想使用 shell 可执行文件来尊重要启动的应用程序的用户首选项,但我还需要知道该特定应用程序何时关闭。

Process editProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = filename;
startInfo.Verb = "edit";
startInfo.UseShellExecute = true;
editProcess.StartInfo = startInfo;

// start the default editor
editProcess.Start();
editProcess.WaitForExit();
Run Code Online (Sandbox Code Playgroud)

WaitForExit 似乎在 shell 进程退出时返回,而不是在真实进程退出时返回。

有没有比手动解析注册表、找到正确的应用程序来启动并显式启动该应用程序而不执行 shell 更好的方法来了解启动的应用程序何时退出?

Dan*_*Dan 1

处理进程退出事件:

editProcess.Exited += process_Exited;
Run Code Online (Sandbox Code Playgroud)