Installing and running a Silverlight application out-of-browser makes it possible to create a better experience to the user. Sometimes it is necessary to update the installed application and with the build-in functionality in Silverlight it is a pretty straight forward operation.
Depending on your application the update should be done early on in the application. Normally I do it as part of the Application Startup event before setting the RootVisual.
First we need to make sure the update is only done if the user is actually running the application out-of-browser. Application.Current.IsRunningOutOfBrowser will be true if the user has installed the application and running it out-of-browser.
On the Application.Current object we can call the CheckAndDownloadUpdateAsync method. This will check if an update is available and download it. The method is an asynchronous method and we need to subscribe on its complete event to complete the update.
If an update is available (and have been downloaded) the UpdateAvailable property of event arguments for the complete event will be true. The update (the new XAP file) have been downloaded but not installed as it is not possible to remove the old XAP file since the user is actually using it to run the application. Therefore the user need to restart the application to install the update.
In some applications it is ok not to require the user to restart the application but in most scenarios it is the preferred solution – think about service updates and so on.
At the moment it is not possible to separate the check and download. It is not possible to check if an update is available and the ask the user if she wish to actually download the update. If the CheckAndDownloadUpdateAsync method is called both check and download will be invoked.
In most debug scenarios this update check will be annoying since the XAP file will be updated everytime you build your project. To overcome this I normally adds an if-not-debug (#if !DEBUG) around the update check.