Question

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
(source: deviantsart.com)

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

You might get what you're wanting by incorporating an external version control check. have it look to see if the version that's installed and the version on the server is different.

If it's different ask the user if they want to update. If they choose yes, then invoke CheckAndDownloadUpdateAsync();

otherwise skip it if they choose no or if the version is the same.

there are many ways to do your own versioning checks. Including static readonly properties that are populated @ build time and have some kind of similar result on an http request.

You could use the webclient to grab a response from the server and compare that with the currently loaded version of the application.

You can incorporate a method on the callback to go to show a message that tells the user to restart the app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top