Export (0) Print
Expand All

Application.CheckAndDownloadUpdateCompleted Event

Silverlight

Occurs when the application has finished checking for updates in response to a CheckAndDownloadUpdateAsync method call.

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

public event CheckAndDownloadUpdateCompletedEventHandler CheckAndDownloadUpdateCompleted
<Application CheckAndDownloadUpdateCompleted="eventhandler"/>

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 following code example demonstrates how to use this event. 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.

Community Additions

ADD
Show:
© 2014 Microsoft