Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Application.CheckAndDownloadUpdateAsync Method

Silverlight

Updated: September 2010

Launches an asynchronous process to check for and download an updated version of the application.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public void CheckAndDownloadUpdateAsync()

Handle the CheckAndDownloadUpdateCompleted event to receive notification when the application has finished checking for an update. In the event handler, the UpdateAvailable property is true if a newer version of the application was discovered and successfully downloaded. In this case, you can alert the user to restart the application in order to load the update.

If an application update is available, but uses a newer version of Silverlight that the user has not yet installed, the update will not be downloaded. This also occurs if an update changes the application to require elevated trust. In both cases, the UpdateAvailable property value is false, and the Error property value is an Exception instance. With a Silverlight version change, the exception is a PlatformNotSupportedException instance. With a security change, the exception is a SecurityException instance. When this happens, you can alert the user to open the application's host Web site, triggering your HTML-based Silverlight upgrade experience.

NoteNote:

In general, you should check for updates only with the consent of the user, and notify the user when an update is available.

The OutOfBrowserSettings.ShortName value must remain the same across multiple versions of an application for the update mechanism to work correctly.

The following code example demonstrates how to use this method. This example is part of a larger example available in How to: Implement Offline Support for Out-of-Browser Applications.


Application app = Application.Current;
public MainPage()
{
    InitializeComponent();
    LayoutRoot.DataContext = Deployment.Current.OutOfBrowserSettings;
    UpdateUI();
    app.CheckAndDownloadUpdateCompleted += 
        App_CheckAndDownloadUpdateCompleted;
    app.InstallStateChanged += (s,e) => UpdateUI();
    NetworkChange.NetworkAddressChanged += 
        (s, e) => UpdateNetworkIndicator();

    MessageBox.Show(Deployment.Current.OutOfBrowserSettings
        .WindowSettings.WindowStyle.ToString());
}


...


private void updateButton_Click(object sender, RoutedEventArgs e)
{
    app.CheckAndDownloadUpdateAsync();
}

private void App_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)
    {
        MessageBox.Show(
            "An application update is available, but an error has occurred.\n" +  
            "This can happen, for example, when the update requires\n" + 
            "a new version of Silverlight or requires elevated trust.\n" + 
            "To install the update, visit the application home page.");
        LogErrorToServer(e.Error);
    }
    else
    {
        MessageBox.Show("There is no update available.");
    }
}

private void LogErrorToServer(Exception ex)
{
    // Not implemented. Logging the exact error to the server can help
    // diagnose any problems that are not resolved by the user reinstalling
    // the application from its home page. 
}


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Date

History

Reason

September 2010

Added note about ShortName requirement.

Customer feedback.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft