Auto update an OOB Silverlight application

So you created an application, have a shortcut to it on your desktop, but whenever you change it, you have to delete the link and create a new one?

This problem can be solved easily. The following code snippet does it for you:

    1. if (Current.IsRunningOutOfBrowser)
    2.       {
    3.         Current.CheckAndDownloadUpdateCompleted += (s, e2) =>
    4.         {
    5.           if (e2.UpdateAvailable)
    6.           {
    7.             MessageBox.Show(“A new version was found, please restart the Application!”);
    8.             if (e2.Error != null)
    9.             {
    10.               MessageBox.Show(“There was an error updating the application!”);
    11.             }
    12.           }
    13.         };
    14.         Current.CheckAndDownloadUpdateAsync();
    15.       }


* This source code was highlighted with Source Code Highlighter.

However, there are some quirks. You shouldn’t check the “Require elevated trust when running outside the browser”, because if you do so, auto update fails to start.

And another one: if you place the code above in the app constructor, it won’t work. The earliest stage I manage to get it work was the Application_Startup method.

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: