Process.WaitForExit 不等待

发布于 2024-10-17 04:21:03 字数 316 浏览 1 评论 0原文

我有以下代码,并且 WaitForExit 方法没有等待。它只是运行命令并继续执行下一条语句。该命令用于卸载应用程序,参数用于卸载命令。卸载运行良好,但我需要在继续之前完成卸载......它不会阻塞。

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = commandName;
startInfo.Arguments = parms;
Process process = Process.Start(startInfo);
process.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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你再特殊 2024-10-24 04:21:03

我强烈怀疑安德烈的评论是正确的 - 您正在启动的进程正在退出,但本身已经启动了一个新进程。

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

您可能想要循环,短暂休眠,同时等待卸载完成的另一个指示 - 例如删除特定文件或注册表项。并不理想,但它可能是您拥有的最好的。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文