Out of browser self updating – it couldn’t be easier!

Former Slalom Consulting Practice Lead Peter Tweed

Peter Tweed was a Practice Lead for Technology Enablement in Slalom Consulting's San Franciso office when he wrote this post.

by Peter Tweed

One of the great features of Silverlight is that an application can be developed to be run in or outside of the browser.  If it runs in the browser, the latest version of the application that is deployed to the web site is automatically used as it is downloaded immediately.  What happens if the Silverlight application has the ability to run out of browser and the user has installed it locally?  Historically it has always been a challenge to either write the solution yourself or in more recent years use click once for client side applications.

In Silverlight it is very easy to take care of when the application has the ability to run out of browser.  This post will show you how to incorporate code to make the application check for and automatically download an updated version.  Steps:

1. Create a new Silverlight project and in the project properties, select the enable running application out of the browser check box

enable running application out of browser

2. In the grid in the MainPage.xaml file copy the following XAML

<br />
&lt;Border BorderThickness=&quot;10&quot; CornerRadius=&quot;10&quot; BorderBrush=&quot;#FF934117&quot;&gt;<br />
    &lt;Border.Background&gt;<br />
        &lt;LinearGradientBrush EndPoint=&quot;0.5,1&quot; StartPoint=&quot;0.5,0&quot;&gt;<br />
            &lt;GradientStop Color=&quot;#FFE80606&quot; Offset=&quot;0&quot; /&gt;<br />
            &lt;GradientStop Color=&quot;#FF8D0202&quot; Offset=&quot;1&quot; /&gt;<br />
        &lt;/LinearGradientBrush&gt;<br />
    &lt;/Border.Background&gt;<br />
    &lt;TextBlock Text=&quot;If an update is available a popup will appear!&quot; VerticalAlignment=&quot;Center&quot; FontSize=&quot;30&quot; TextAlignment=&quot;Center&quot; TextWrapping=&quot;Wrap&quot; &gt;<br />
&lt;/Border&gt;<br />

This code does nothing more than give a simple UI for the application.

3. Open the App.xaml.cs file

4. Replace the Application_Startup event handler with the following code

<br />
private void Application_Startup(object sender, StartupEventArgs e)<br />
{<br />
    this.RootVisual = new MainPage();<br />
    App.Current.CheckAndDownloadUpdateCompleted+=new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);<br />
    App.Current.CheckAndDownloadUpdateAsync();<br />
}<br />

This code declares the event handler for the completed event for when the current application object checks for updates automatically and downloads any available update.  The current application then checks for any updates and automatically downloads them.4. Paste the following function in the App class

<br />
void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)<br />
{<br />
    if (e.UpdateAvailable)<br />
    {<br />
        MessageBox.Show(&quot;An application update is available, please restart your application&quot;, &quot;Update Available&quot;, MessageBoxButton.OK);<br />
    }<br />
}<br />

This code defines the event handler to call when the application has checked for updates.  The developer can interogate the event argument to see if an update was downloaded and if so perform some logic.  In this case we inform the user they need to restart the application.

5. Run the application and right click it and select “Install application [Your App Name] onto this computer…”

run 11

6. Close the application that installed and ran on your computer and the browser version as well

7. Add a comment to the code in the app class and rebuild the application

8. Run the application installed on your computer

run 2

The application should raise the message box above telling you an update was automatically downloaded and you need to restart your application.

9. Restart your client installed application – you will not be shown a pop up about an automated update as none is available.

That’s it.  Making your out of browser client installed Silverlight application automatically update and handle custom logic after an update has been downloaded is extremely simple.  No deployment configuration is needed other than telling the application to run out of browser in the project properties window.

-Peter

About Slalom Consulting
Slalom Consulting brings business and technology expertise together to help companies drive enterprise performance, accelerate innovation, enhance the customer experience, and increase employee productivity. We deliver award-winning solutions in areas such as business intelligence, mobility, and cloud through a national network of local offices across 10 North American cities. Founded in 2001 and based in Seattle, WA, Slalom has rapidly grown to more than 1,100 employees and has earned recognition from Microsoft as the "United States Partner of the Year" and "Online Services Partner of the Year," as well as one of the "Top 10 Best Firms to Work For" by Consulting Magazine. For more information, please visit www.slalom.com.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 129 other followers

%d bloggers like this: