clickonce部署后的手动更新代码

 

ExpandedBlockStart.gif ContractedBlock.gif   /**/ /// <summary>
InBlock.gif        
/// 检测网络更新
ExpandedBlockEnd.gif        
/// </summary>

None.gif          private   void  InstallUpdateSyncWithInfo()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            UpdateCheckInfo info 
= null;
InBlock.gif
InBlock.gif
InBlock.gif            
if (ApplicationDeployment.IsNetworkDeployed)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ApplicationDeployment ad 
= ApplicationDeployment.CurrentDeployment;
InBlock.gif
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    info 
= ad.CheckForDetailedUpdate();
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch (DeploymentDownloadException dde)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    MessageBox.Show(
"软件升级发现异常. \n\n请检测网络情况后重新升经. 错误原因为:" + dde.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch (InvalidDeploymentException ide)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    MessageBox.Show(
"网络中无法检测到可更新的部署文件,请与软件开发商联系. 错误原因: " + ide.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch (InvalidOperationException ioe)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    MessageBox.Show(
"软件无法更新. 请与软件开发商联系. 错误原因: " + ioe.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
if (info.UpdateAvailable)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Boolean doUpdate 
= true;
InBlock.gif
InBlock.gif                    
if (!info.IsUpdateRequired)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        DialogResult dr 
= MessageBox.Show("检测到新版本,版本号为:" + info.AvailableVersion.ToString() + ",是否现在升级?""升级检测", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
InBlock.gif                        
if (!(DialogResult.OK == dr))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            doUpdate 
= false;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

InBlock.gif
InBlock.gif                    
if (doUpdate)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            ad.Update();
InBlock.gif                            MessageBox.Show(
"升级完毕,请重启软件以使用新版本.""升级检测", MessageBoxButtons.OK, MessageBoxIcon.Information);
InBlock.gif                            Application.Restart();
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
catch (DeploymentDownloadException dde)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            MessageBox.Show(
"软件升级发现异常. \n\n请检测网络情况后重新升经. 错误原因为: " + dde, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
InBlock.gif                            
return;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    MessageBox.Show(
"您现在使用的已经是最新版本软件!""升级检测", MessageBoxButtons.OK, MessageBoxIcon.Information);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"不是网络部署软件,无法更新""升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/forrestsun/articles/569586.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值