Andrej Tozon's blog

In the Attic

NAVIGATION - SEARCH

Countdown to Silverlight 3 #1: Out of Browser applications

With Silverlight 3 knocking on the door (July 10?) it’s time to offload my Silverlight 3 examples. Not that they would show anything new (since SL3 Beta got out, new features had been demoed by various people to the death), it’s just another perspective or a way to go public with a sample code that’s been piling up on my desktop since the Beta was released. Anyway, this will be in a form of short posts with provided test page and sample code.

I’ll begin with probably the most talked about new feature – Out of Browser applications, which could also be referred to as installed applications.

First of – not every Silverlight application can be installed on the client machine. The developer must enable this by adding a <Deployment.Application> section to the application manifest (AppManifest.xml). This section provides more information about the application (name, title, description), along with optional icons in a few different sizes, which are used for branding your application and are displayed on various places on the desktop (install dialog, application shortcut, title bar, …)

Alternative way to installing the application (a common way is to install it through the Silverlight application right-click context menu) is to provide the user with a button of some sort, which would call the new Application.Current.Detach() method when clicked. Note that the method requires an explicit user action to succeed; calling it on the application load or perhaps inside a timer tick event should fail with the exception.

There’s the Application.Current.ExecutionState property telling the installation state of the application. Possible values include RunningOnline (not installed, the default), Detaching, Detached, DetachedUpdatesAvailable and DetachFailed (for describing various installed/ing states).

When installed, the application can be run as before, inside the browser, or, by calling it through a created shortcut (start menu, desktop), outside the browser. Inspecting the Application.Current.RunningOffline property will tell you how the application was run.

To check if application is connected to the network, there’s the NetworkInterface.GetIsNetworkAvailable() method, returning a simple true or false. Remember that being connected to the network doesn’t mean application has access to the internet, and certainly doesn’t imply that a network resource or a service application wants to call is accessible at all.

One last thing to mention is that Out of Browser application still run in a partial trust, the same security context as it would when run inside the browser. The isolated storage quota, however, increases to 25MB when application gets installed.

Additional reading
http://timheuer.com/blog/archive/2009/03/18/silverlight-3-offline-update-framework.aspx
http://msdn.microsoft.com/en-us/magazine/dd882515.aspx

Run the sample online

Source code below: