pubic static int returnCode = 0;
private bool appUpdater1_OnCheckForUpdate(object sender, System.EventArgs e)
{bool isUpd; //是否可以更新
string strUpdUrl; //更新地址
// 声明service对象
UpdateWeb.UpdateService updateService = new UpdateWeb.UpdateService();
//获得service地址
string strUrl = System.Configuration.ConfigurationManager.AppSettings["updateurl"];
updateService.Url = strUrl;
//判断更新地址是否可用
isUpd = updateService.CheckForUpdate(
Microsoft.Samples.AppUpdater.AppUpdater.GetLatestInstalledVersion().ToString(), Application.ProductName , out strUpdUrl);
//地址可用
if (isUpd == true)
{
appUpdater1.UpdateUrl = strUpdUrl;
}
//返回结果
return isUpd;
}
private void appUpdater1_OnUpdateComplete(object sender, Microsoft.Samples.AppUpdater.UpdateCompleteEventArgs e)
{
//更新成功
if ( e.UpdateSucceeded)
{
if (MessageBoxs.ShowQuestionMessage("更新完成,需要关闭程序后重新启动,否则容易造成错误,是否要关闭程序?") == DialogResult.Yes)
{
//返回操作Code
returnCode = Microsoft.Samples.AppUpdater.AppUpdater.RestartAppReturnValue;
this.Close();
}
}
else//更新失败.
{
MessageBoxs.ShowErrorMessage("程序更新失败!");
}
}
private void appUpdater1_OnUpdateDetected(object sender, System.EventArgs e)//**********检测到新版本
{
if (MessageBoxs.ShowQuestionMessage("发现一个新的版本,是否进行更新?") == DialogResult.Yes)
{
appUpdater1.DownloadUpdate();
}
}
reference.cs:
public bool CheckForUpdate(string clientVersion, string ClientName, out string updateUrl)
{
object[] results = this.Invoke("CheckForUpdate", new object[] {
clientVersion,
ClientName});
updateUrl = ((string)(results[1]));
return ((bool)(results[0]));
}