One of the challenges when developing an application is to give visual indication while a long running process is occurring. In Silverlight this can be easily achieved using the RadBusyIndicator control. However, the UI thread sometimes gets frozen. While the UI thread is frozen no control can be animated which means that the RadBusyIndicator’s animation will freeze too and this will lead to unpleasant user experience. One of the greatest enhancements introduced with Silverlight 5 was the concept of Composition thread - it allows you to animate certain elements using the GPU instead of the UI thread. This can be pretty useful when you want to show a progress bar while some heavy UI related logic is running.

In the next bullet points I will try to explain how to avoid the annoying freeze of the RadBusyIndicator while the UI thread is frozen.

  • First of all, you have to turn on the GPU acceleration. Open the aspx (or html) page that hosts your Silverlight application and make sure that the enableGpuAcceleration parameter is set to true. If this parameter is not added, you will have to add it yourself.

    <param name="enableGpuAcceleration" value="True" />

  • In order to animate a certain UI element on the GPU we have to set its CacheMode to BitmapCache. Because of this, the RadBusyIndicator’s style has to be extracted and modified using Blend or Visual Studio 2012. For example, into the RadBusyIndicator’s default theme the animated element is a Path and it is named “IndeterminateDonut”. So, we have to simply change its CacheMode to BitmapCache. Here is a sample code snippet of the required changes:

    <Path x:Name="IndeterminateDonut" … > 
            <BitmapCache /> 

As you see animating elements in Silverlight 5 on the GPU is a great and simple task that requires only a few steps.

The described approach has some limitations that should be noted. When using the described approach in Internet Explorer the RadBusyIndicator sometimes fully freezes or for the last 2 seconds of the 5 sec Thread.Sleep. This is a know limitation that is present only in Internet Explorer and currently there isn't a known workaround for it.

A sample project that demonstrates this approach can be downloaded via this link AnimateOnFrozenUI.

About the Author

Ivelin Davidov

 is Software Developer. 

Related Posts


Comments are disabled in preview mode.