Navigation


Markus on Development and Publishing

This is Markus Egger's professional blog, which covers topics such as development, publishing, and business in general. As the publisher of CoDe and CoDe Focus magazines, and as the President and Chief Software Architect of EPS Software Corp., Markus shares his insights and opinions on this blog.

Content Area Footer

Wednesday, August 25, 2010
Auto-Updating a Silverlight Out-Of-Browser App

Silverlight supports Out-Of-Browser operation, meaning you can build an app that runs very much like a desktop application. You enable this via a simple setting in the properties of the Silverlight control. Once you have an OOB app, you can either start it as a stand alone app, or, if the app is originally launched within a browser as part of a page, users can right-click on it and choose to “install the app locally”.

I really like this feature. But I was surprised to learn that an app taken out of the browser does not automatically update itself when a newer version is available on the server. It always seems to me that is the quintessential modus operandi in Silverlight. After all, in the web browser, when you navigate to a site with a Silverlight control, you automatically and always get the latest version of that control. Versions that have been cashed from prior visits are only used if the version is still up to date. Not so for OOB Silverlight apps. You can publish new versions all you want, the client (by default) has the version that was originally installed.

So what do you do to fix this problem? Well, luckily it turns out you can simply add a few lines of code to the app’s constructor to enable updating. Add the following code to your App class’ constructor (in App.xaml.cs) to get auto-updating:

if (Current.IsRunningOutOfBrowser)
{
    Current.CheckAndDownloadUpdateCompleted += (sender, e) =>
        {
            if (e.Error == null && e.UpdateAvailable)
                MessageBox.Show("New version! Please restart!");
        };
    Current.CheckAndDownloadUpdateAsync();
}

So the whole constructor part of the app class should now look like this:

public partial class App : Application
{
    public App()
    {
        Startup += Application_Startup;
        Exit += Application_Exit;
        UnhandledException += Application_UnhandledException;

        InitializeComponent();

        if (Current.IsRunningOutOfBrowser)
        {
            Current.CheckAndDownloadUpdateCompleted += (sender, e) =>
                {
                    if (e.Error == null && e.UpdateAvailable)
                        MessageBox.Show("New version! Please restart!");
                };
            Current.CheckAndDownloadUpdateAsync();
        }
    }
    // …

There you go! Live is good again :-)



Posted @ 10:13 AM by Egger, Markus (markus@code-magazine.com)


 

 

 

 

 

 

 



My Twitter Status


    follow me on Twitter  


    Geo Caching
    Profile for MarkusEgger

    Syndication ng> RSS 2.0 RSS 2.0

    All My Blogs:
    My personal blogs:
    Dev and Publishing Dev and Publishing
    Travel and Internat. Living Travel and Internat. Living
    Other blogs I contribute to:
    Milos Blog (US) Milos Blog (US)
    VFPConv. Dev Blog (US) VFPConv. Dev Blog (US)
    VFPConv. Dev Blog (DE) VFPConv. Dev Blog (DE)

     

    Blog Archives
    All Blog Posts

    2012
        September (1)
        April (1)
        March (1)
    2011
        October (1)
        June (3)
        May (1)
        March (2)
        February (2)
        January (2)
    2010
        December (3)
        November (2)
        October (2)
        September (1)
        August (2)
        July (1)
        June (1)
        April (3)
        March (1)
        February (5)
        January (1)
    2009
        October (4)
        September (2)
        August (1)
        July (1)
        May (4)
        April (6)
        February (1)
        January (1)
    2008
        December (3)
        November (11)
        October (8)
        September (1)
        July (1)
        June (3)
        May (3)
        April (6)
        March (6)
        February (4)
    2007
        December (1)
        November (1)
        October (5)
        September (1)
        August (1)
        July (6)
        June (3)
        May (3)
        April (1)
        March (2)
        January (2)
    2006
        December (3)
        November (4)
        October (1)
        September (2)
        August (2)
        July (4)
        June (1)
        May (2)
        April (10)
        March (2)
        February (3)
        January (1)
    2005
        December (6)
        November (7)
        October (6)
        September (8)
        August (10)
        July (6)
        June (9)

     

     

     

    This Blog is powered by MilosTM Collaboration Components.