private void OnCheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.UpdateAvailable && e.Error == null)
{
MessageBox.Show("应用新版本已经下载成功,将在下次启动时生效。");
}
else if (e.Error != null)
{
MessageBox.Show("在检测应用更新时, 在"
+ "出现以下错误信息:"
+ Environment.NewLine
+ Environment.NewLine
+ e.Error.Message);
}
}
然后,添加声明在App的构造函数中,使其在安装时进行版本更新检查:
public App()
{
if (App.Current.InstallState == InstallState.Installed)
{
App.Current.CheckAndDownloadUpdateCompleted += OnCheckAndDownloadUpdateCompleted;
App.Current.CheckAndDownloadUpdateAsync();
}
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}