/**/
/// <summary>
/// 检测网络更新
/// </summary>
private
void
InstallUpdateSyncWithInfo()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
UpdateCheckInfo info = null;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (ApplicationDeployment.IsNetworkDeployed)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
info = ad.CheckForDetailedUpdate();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
catch (DeploymentDownloadException dde)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("软件升级发现异常. \n\n请检测网络情况后重新升经. 错误原因为:" + dde.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
catch (InvalidDeploymentException ide)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("网络中无法检测到可更新的部署文件,请与软件开发商联系. 错误原因: " + ide.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
catch (InvalidOperationException ioe)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("软件无法更新. 请与软件开发商联系. 错误原因: " + ioe.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (info.UpdateAvailable)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Boolean doUpdate = true;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (!info.IsUpdateRequired)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DialogResult dr = MessageBox.Show("检测到新版本,版本号为:" + info.AvailableVersion.ToString() + ",是否现在升级?", "升级检测", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (!(DialogResult.OK == dr))
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
doUpdate = false;
}
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (doUpdate)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ad.Update();
MessageBox.Show("升级完毕,请重启软件以使用新版本.", "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Restart();
}
catch (DeploymentDownloadException dde)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("软件升级发现异常. \n\n请检测网络情况后重新升经. 错误原因为: " + dde, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("您现在使用的已经是最新版本软件!", "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("不是网络部署软件,无法更新", "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
转载于:https://www.cnblogs.com/forrestsun/articles/569586.html