【发布时间】:2014-12-09 05:11:07
【问题描述】:
我正在构建一个 c# 控制台应用程序,它会自动查找更新、下载并安装它们。
我在安装部分使用这种方法:
public static void InstallUpdates(UpdateCollection DownloadedUpdates)
{
UpdateSession UpdateSession = new UpdateSession();
UpdateInstaller InstallAgent = UpdateSession.CreateUpdateInstaller() as UpdateInstaller;
InstallAgent.Updates = DownloadedUpdates;
//Starts a synchronous installation of the updates.
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa386491(v=VS.85).aspx#methods
IInstallationResult InstallResult = InstallAgent.Install();
}
根据this链接,我可以检查是否需要重新启动。我想要实现的是在 RebootRequiredBeforeInstallation 更改为 true 时立即完成系统重启。
我想过这样做,但那行不通,因为我不能使用 else 语句:
while (!InstallAgent.RebootRequiredBeforeInstallation)
{
} else
{
// Reboot
}
解决这个问题的正确方法是什么?
【问题讨论】:
-
为什么不能在
while循环中使用if-else? -
@xxbbcc 起初我认为 if-else 语句会立即运行,而不是在一段时间后运行 - 但我越想越意识到在安装完成。对吗?
标签: c# windows api console windows-update