Automatic Updates for Silverlight 3 – Out of Browser (SLOOB)
After playing around with Silverlight at work. I have come to really enjoy the out-of-browser experience. After updating my applications a few times, I notice that users running the app OOB were not receiving any updates. I thought this was all automagic, but I was proved wrong. After doing a little binging around I stumbled on the CheckAndDownloadUpdateAsync method. I took this example and popped it in my loaded event of my main navigation page, which looked a little like this.
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (Application.Current.IsRunningOutOfBrowser)
{
Application.Current.CheckAndDownloadUpdateCompleted += UpdateCompleted;
Application.Current.CheckAndDownloadUpdateAsync();
}
}
private void UpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if(e.UpdateAvailable)
MessageBox.Show("A new version of this cool application has been downloaded. Please restart to run the updated version");
}
After adding this event I was sure enough we were going to start getting some updates, but this still wasn’t the case. After doing some more fiddling around with this I found out that you have to update the version number, which I usually keep the Assembly Version and the File Version the same. Unlike ClickOnce where it increments a published version number on publish, so far I find that you have to do this yourself.
After updating the version, I rebuilt my SL application then republished my Web Application. Doing this gave me the results I was expecting. This all seems very simple and it works great for me, but if your doing this for the first time you might find that there isn’t many examples floating around quite yet.
I would like to add a disclaimer saying this is my first technical blog post, so any tips, constructive criticism or suggestions would be appreciated.
(sorry for the small code block font... working on that to make it bigger)