Process.WaitForExit不等待 [英] Process.WaitForExit not waiting

查看:83
本文介绍了Process.WaitForExit不等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,并且WaitForExit方法未等待。它只是运行命令并继续执行下一条语句。该命令用于取消安装应用程序,而参数用于卸载命令。卸载运行良好,但我需要卸载完成后才能继续...它没有阻止。

I have the following code and the WaitForExit method is not waiting. It just runs the command and moves on to the next statement. The command is to unintall an application and the parms are for the uninstall command. The uninstall runs fine but I need the uninstall to finish before moving on...it's not blocking.

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = commandName;
startInfo.Arguments = parms;
Process process = Process.Start(startInfo);
process.WaitForExit();


推荐答案

我强烈怀疑Andrey的评论正确-该过程您正在开始正在退出,但是本身已经启动了一个新过程。

I strongly suspect that Andrey's comment is right - the process you're starting is exiting, but having started a new process itself.

简单的发现方法是打印 process.Id ,然后调用 WaitForExit ,然后尝试在任务管理器中找到该进程。我怀疑您会发现它不会在那里。

The simple way to find that out is to print out process.Id before calling WaitForExit, and then try to find that process in task manager. I suspect you'll find it won't be there.

您可能想循环一下,在等待另一项卸载完成的迹象时短暂睡眠-例如特定文件或注册表项被删除。不理想,但这可能是您最好的。

You may want to loop round, sleeping briefly while waiting for another indicator of the uninstall being finished - such as a particular file or registry entry being removed. Not ideal, but it may be the best you've got.

这篇关于Process.WaitForExit不等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆