Process.WaitForExit 不等待
我有以下代码,并且 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我强烈怀疑安德烈的评论是正确的 - 您正在启动的进程正在退出,但本身已经启动了一个新进程。
找到该进程的简单方法是在调用
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 callingWaitForExit
, 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.