views:

79

answers:

2

I have made an out-of-browser silverlight application which I want to automatically update every time there is a new .xap file uploaded to the server.

When the user right-clicks the application and clicks on Updates, the default is set to "Check for updates, but let me choose whether to download and install them":

alt text

This leads me to believe that it is possible to make my Silverlight application automatically detect if there is a new .xap file present on the server, and if there is, the Silverlight client will automatically ask the user if he would like to install it.

  • This however is not the case. I upload a new .xap file and the Silverlight application does nothing.

  • Even if I add this to my App.xaml.cs:

--

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new BaseApp();
    if (Application.Current.IsRunningOutOfBrowser)
    {
        Application.Current.CheckAndDownloadUpdateAsync();
    }
}

and update the .xap file, the Silverlight application does nothing.

  • This information enabled me to check if there is an update and if so, tell the user to restart the application, but when he restarts the application, nothing happens:

--

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
    }
}

How do I make my Silverlight application check, each time it starts, if there is a new .xap file, and if there is, pass control to the Silverlight client to ask the user if he wants to download it, as the above dialogue implies is possible?

+1  A: 

The screen you are refering to the is not specific to any silverlight application. Its refering to the silverlight plugin itself.

The CheckAndDownloadUpdateAsync method should have downloaded the newer version but the user will need to restart the application in order to start using the new application. You use the UpdateAvailable property of the event args in the completed event to determine whether to ask the user to restart.

AnthonyWJones
+1  A: 

The first dialog is about how updates to Silverlight itself are installed and has nothing to do with your application.

Using the CheckAndDownloadUpdateAsync the new XAP should be downloaded automatically. Acording to the doc there is no way to prevent the new version from being installed one you call CheckAndDownloadUpdateAsync.

Maurice