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