我制作了一个浏览器外的silverlight应用程序,每次有新的 .xap 文件上传到服务器时,我想自动更新它。
当用户右键单击应用程序并单击Updates时,默认设置为“检查更新,但让我选择是否下载并安装它们”:
(来源:deviantsart.com)
这让我相信可以让我的 Silverlight 应用程序自动检测服务器上是否存在新的 .xap 文件,如果有,Silverlight 客户端会自动询问用户是否要安装它。
然而事实并非如此。我上传了一个新的 .xap 文件,而 Silverlight 应用程序什么也不做。
即使我将此添加到我的App.xaml.cs:
--
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new BaseApp();
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateAsync();
}
}
并更新 .xap 文件,Silverlight 应用程序什么也不做。
- 此信息使我能够检查是否有更新,如果有,请告诉用户重新启动应用程序,但是当他重新启动应用程序时,什么也没有发生:
--
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new BaseApp();
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateAsync();
Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
}
}
void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.UpdateAvailable)
{
MessageBox.Show("An application update has been downloaded. " +
"Restart the application to run the new version.");
}
else if (e.Error != null &&
e.Error is PlatformNotSupportedException)
{
MessageBox.Show("An application update is available, " +
"but it requires a new version of Silverlight. " +
"Visit the application home page to upgrade.");
}
else
{
//no new version available
}
}
如何让我的 Silverlight 应用程序在每次启动时检查是否有新的 .xap 文件,如果有,将控制权传递给 Silverlight 客户端,询问用户是否要下载它,如上面的对话所示有可能吗?