Monday, July 27, 2009

Silverlight 3 : Analytics Class Capabilities

I hope my last article on Out of Browser breaking changes was useful for you, Today I am going to talk about the Analytics Class provided by Silverlight 3 with a very small demo. For this, you don’t need anything special since Analytics class is already made available as built-in once you install Silverlight 3.

About Analytics Class :

You will find this under System.Windows Namespace,So you don’t need any other references to set inside your project beside System.Windows.This class exposes two main properties as :

  • AverageProcessorLoad - Gets how much of the CPU this process is using across all cores averaged together (This might be directly applicable for Multi-core processors environment,mine is Centrino machine and not Core 2, but results are averaged as per definition)
  • AverageProcessLoad - Gets how much CPU processing is being used across all cores averaged together.

Another one is there known as GPUCollection which is though not part of my demo, but it is used to get a collection of GpuInformation objects which each include details taken from a video driver. The collection is useful for multi-adapter cases. For more information on Analytics Class, kindly refer Silverlight Offline documentation.

In my demo, I have also used some of the properties of Media Element Control which generally people don’t use since for scenarios of just playing videos they might not be applicable. Those properties are self-explanatory so again refer documentation if you need any more information. Now our Demo

XAML Code :

<Grid x:Name="LayoutRoot" Background="White">
       <MediaElement x:Name="MyMedia" Height="154" AutoPlay="True" Source="Wildlife.wmv" Margin="3,8,279,0" VerticalAlignment="Top" />
       <Rectangle Stroke="Black" Margin="6,166,8,8">
               <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                   <GradientStop Color="Black" Offset="0"/>
                   <GradientStop Color="#FF99ABFF" Offset="1"/>
                   <GradientStop Color="#FFF8EAFA"/>
       <dataInput:Label x:Name="compcpu" HorizontalAlignment="Left" Margin="19,193,0,0" Width="120" Content="Computer CPU Usage" Height="20" VerticalAlignment="Top"/>
       <dataInput:Label x:Name="slcpu" HorizontalAlignment="Right" Margin="0,0,509,185" VerticalAlignment="Bottom" Content="Silverlight CPU Usage"/>
       <ProgressBar x:Name="pgbar1" Margin="154,193,286,0" Height="20" VerticalAlignment="Top"/>
       <ProgressBar x:Name="pgbar2" Margin="154,0,286,184" Height="20" VerticalAlignment="Bottom"/>
       <dataInput:Label x:Name="gpucpu" HorizontalAlignment="Left" Margin="21,0,0,154" VerticalAlignment="Bottom" Content="Download Progress"/>
       <ProgressBar x:Name="pgbar3" Height="20" Margin="155,0,285,150" VerticalAlignment="Bottom"/>
       <dataInput:Label HorizontalAlignment="Left" Margin="23,0,0,116" VerticalAlignment="Bottom" Content="Audio Stream Count :"/>
       <dataInput:Label HorizontalAlignment="Left" Margin="23,0,0,97" VerticalAlignment="Bottom" Height="13" Content="Buffering Progress :"/>
       <dataInput:Label HorizontalAlignment="Left" Margin="23,0,0,72" VerticalAlignment="Bottom" Content="Buffering Time :"/>
       <dataInput:Label HorizontalAlignment="Left" Margin="23,0,0,50" VerticalAlignment="Bottom" Content="Dropped Frame Per Second :"/>
       <dataInput:Label x:Name="txtBufferingTime" HorizontalAlignment="Left" Margin="212,0,0,71" VerticalAlignment="Bottom"/>
       <dataInput:Label x:Name="txtBufferingProgress" HorizontalAlignment="Left" Margin="213,0,0,92" VerticalAlignment="Bottom"/>
       <dataInput:Label x:Name="txtAudioStreamCount" HorizontalAlignment="Left" Margin="213,0,0,114" VerticalAlignment="Bottom"/>
       <dataInput:Label x:Name="txtDFPS" HorizontalAlignment="Left" Margin="212,0,0,49" VerticalAlignment="Bottom"/>
       <dataInput:Label Margin="0,0,238,26" VerticalAlignment="Bottom" HorizontalAlignment="Right" Content="Natural Video Width :"/>
       <dataInput:Label Margin="0,0,238,49" VerticalAlignment="Bottom" HorizontalAlignment="Right" Content="Natural Video Height :"/>
       <dataInput:Label Margin="0,0,238,116" VerticalAlignment="Bottom" HorizontalAlignment="Right" Content="Natural Duration :"/>
       <dataInput:Label Margin="23,0,0,26" VerticalAlignment="Bottom" Content="Current State :" HorizontalAlignment="Left"/>
       <dataInput:Label x:Name="txtCurrentState" Margin="213,0,0,25" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
       <dataInput:Label x:Name="txtNtrlDur" Margin="0,0,94,115" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
       <dataInput:Label x:Name="txtNVH" Margin="0,0,94,46" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
       <dataInput:Label x:Name="txtNVW" Margin="0,0,94,23" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>

C# Code :

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Silverlight3NewFeature
    public partial class Page : UserControl
        Analytics analytics;

        public Page()
            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);           

        void CompositionTarget_Rendering(object sender, EventArgs e)
            if (analytics == null)
                analytics = new Analytics();
                pgbar1.Value = analytics.AverageProcessorLoad;
                pgbar2.Value = analytics.AverageProcessLoad;
                pgbar3.Value = MyMedia.DownloadProgress;

                txtAudioStreamCount.Content = MyMedia.AudioStreamCount;
                txtBufferingTime.Content = MyMedia.BufferingTime;
                txtBufferingProgress.Content = MyMedia.BufferingProgress;
                   txtDFPS.Content = MyMedia.DroppedFramesPerSecond;
                txtCurrentState.Content = MyMedia.CurrentState;
                txtNtrlDur.Content = MyMedia.NaturalDuration;
                txtNVH.Content = MyMedia.NaturalVideoHeight;
                txtNVW.Content = MyMedia.NaturalVideoWidth;


A surprise for few of you for that CompositionTarget_Rendering Event, Well CompositionTarget exposes one and only one event which we are using and which occurs when the core Silverlight rendering process renders a frame, Since both the properties of Analytics class which we are using are directly reflecting value which can get change at each instance (i.e CPU and Process Load). So Loaded event might not be a suitable event for such requirement. Please note that, I am aware that values from Analytics class returns float value and not complete integer, But my idea is to show overall average consumption, so I opt ProgressBar control and not label.

Few of you may not be impress by so many labels and may wish to print all values on some TextBlock under some stackpanel, Well then this code might be good for you :

String str;

str = "Audio Stream Count :" + MyMedia.AudioStreamCount + "\n"
    + "Buffering Progress :" + MyMedia.BufferingProgress + "\n"
    + "Buffering Time :" + MyMedia.BufferingTime + "\n"
    + "Dropped Frame Per Second :" + MyMedia.DroppedFramesPerSecond + "\n"
    + "Current State :" + MyMedia.CurrentState + "\n"
    + "Natural Duration :" + MyMedia.NaturalDuration + "\n"
    + "Natural Video Height :" + MyMedia.NaturalVideoHeight + "\n"
    + "Natural Video Width :" + MyMedia.NaturalVideoWidth + "\n";

and then assign that str to any of TextBlock as Text property.

Output will look like this :


I hope this small demo will help you to understand the capabilities of Analytics class in Silverlight 3, I will be back with much more soon.


Friday, July 24, 2009

Silverlight 3 : Out Of Browser

I have already written an article over Silverlight Out Of Browser functionality few months back ( , Now I am rewriting it due to some Breaking Changes from Beta to RTW of Silverlight 3. The working principle and the architecture remains same as it was in Beta, but way of execution is bit different for RTW. Do read my previous article to find out more on sllauncher.exe file, now in RTW you can see this sitting outside framework folder like this :


With Silverlight 3 RTW, now you don’t need to put configuration inside “AppManifest.xaml” , you have a full fledge wizard to handle those settings which you can find inside Project Properties option like this :


Here you can find all settings including Icons, you can browse those, you can set Width and Height along with title. Some of my enthusiast friends wend ahead and try to did this config by means of old way in AppManifest.xaml, At first hit of F5 they told me that look it runs without any compile error ! so it can be done ! ..but after few seconds, nothing was happen and then I shown them in status bar that we have error nicely put forth like this :


Now let’s talk about doing this via code, previously it was :

App.Current.Detach(); now it is replaced by App.Current.Install

You also have one boolean property as InstallState which gets the current installation state of the application. As far as network capabilities are concern NetworkChange.NetworkAddressChanged event and NetworkInterface.GetIsNetworkAvailable() are intact to monitor network connectivity of application.

Code snippet like following will help you to understand which mode application is in currently :

if (App.Current.IsRunningOutOfBrowser)
                Reftext.Text = "Out of Browser";
                Reftext.Text = "In Browser";

Rest of the things as far as working principles are concern are same as it was in Beta environment.

Some point I would like you to focus on while developing this kind of OOB apps.

1. I encourage you to read more on ShowInstallMenuItem="False" which is an attribute inside OutOfBrowser.xml file which you can see inside your project. Find out in documentation, what this is capable of doing.

2. Read more on Application.CheckAndDownloadUpdatesAsync() along with its corresponding event handler CheckAndDownloadUpdatesCompleted and what capabilities they own. These two might be key terms who will play a vital role in your OOB Silverlight apps.

For the last point (2nd), I encourage you to visit Ashish Shetty’s blog who is part of SL Team and he wrote very good articles especially on OOB functionality, He covers all aspects from Developers as well as from Architectural point of view, Here is URL :

I will very soon talking about other breaking changes while you migrate from Beta to RTW, I hope this will help you and reduce your migration pain, will talk on other things soon.


Saturday, July 18, 2009

What’s going on in RIA World ?

This blog post I am starting with one bad news..and news is that Microsoft Popfly Service (Remember Popfly? We use to create Jazzy Mashups and small cool games, I even wrote one post on it in past ) is now closing down soon in August.

Well not to worry much about it. I made few posts on Silverlight 3 since it was in Beta version, In my last post I give out the links to download Silverlight SDK and tools so that you can get ready with Silverlight 3 environment. I am in process to write separate series of article for Blend 3 and Sketch Flow,mostly in next week.

Breaking Changes in Silverlight !

Few of my friends already breaking their head because of breaking changes ! :P

Today,to start with let us just discuss what all new things there with the Silverlight 3 RTW build, and then as usual we will go deep down for each one, I believe in experimenting few things and not just push to my post are sometimes comes late to your side, well I take my own time :)

Out of Browser : Revamped !

Following statements if you are using to check if application is running offline :

if(App.Current.RunningOffline){} will not work with new bits.

App.Current.RunningOffline is now replaced by App.Current.IsRunningOutOfBrowser

Same story for App.Current.Detach(), its now App.Current.Install(), This is also given us new event to handle as InstallStateChanged. Also in addition to this, the old way of configuring of AppManifest.xaml for Out of Browser is now revamp with a separate Configuration Window under Visual Studio and can be access as Project –> Project Properties like this :


Note : “Reduce XAP Size” and “Enable Out of Browser” not goes together hand in hand. Why ? ..we are discussing this in our upcoming post.

OOBSettingsAlso I am keeping my shut on Application.Current.CheckAndDownloadUpdateAsync(); Since very soon I will write a separate post on it which will cover all this breaking changes.

System.Web.Silverlight : R.I.P !

From Silverlight 3 SDK, You will not see <asp:Silverlight/> and <asp:MediaPlayer/> inside your hosting ASP.NET Page. Microsoft now recommends you to use <object> tag (We already have that in our HTML Hosting sample pages,isn’t it? ..Guys this reminds me to search for HTML 5 and keep looking progress of the same, They say its new revolution on Web !, make sure you use Bing and not Google ! :P )

Some of our close Control friends are moved : Silverlight Toolkit !

Following Controls are now part of Silverlight Toolkit :

  • DockPanel

  • WrapPanel

  • Expander

  • ViewBox

  • DataForm

Some more features with Silverlight 3 in short :

  • Supports Browser Zoom

  • Supports Multitouch

  • Supports Matrix Projection

  • Supports Mouse Wheel event

  • New analytics class to identify CPU usage and usage by SL

  • Clear Type Support

So these are few Highlighted features of newly launched Silverlight 3 RTW bits, Don’t get panic, We will explore them one by one in much more depth.

New DeepZoom Composer !

New DeepZoom is now available for download with exciting new features of Tag ( In past I have already talked about usage of DeepZoom, still same method is carried to this version,so you can refer my old blog post ). You can set now Tags to images easily.



By choosing Export option as “Tag Browser” you will get output like this : (Very excellent look and also easily pluggable in App)


Enjoy !!..So..That’s all about Silverlight 3 new stuff and breaking changes, soon I will be talking on SketchFlow and then again Silverlight 3 but not overview but with deep keep looking at this place for much more new stuff !


Friday, July 10, 2009

Welcome to Silverlight 3 RTW and Blend 3 + Sketch Flow

I am happy that my new Silverlight MVP year started with brand new things ! :)

Silverlight 3 is now Ready To Work !! , Yes ! Announcement is already made for new bits of Silverlight 3 RTW along with much awaited Sketch Flow in Blend 3, you can download it from :

Silverlight 3 SDK

Silverlight Tools for Visual Studio 2008 with SP1

Expression Blend 3 + Sketch Flow

For more on Expression Encoder 3

Tim Heuer also published about cool new 7 themes for Silverlight 3 at his blog :

Just make sure while you trying this out that, You should remove all Betas so as to have smooth install experience.

Now following screens might be tempting ! but wait..lot to come now here on at this keep looking here and enjoy following Screens..

Blend 3 install



Meanwhile let me go and explore new things and get back to you soon :)


Friday, July 3, 2009

I am Silverlight MVP !!!

I am happy to tell all my blog readers that I am now Microsoft Most Valuable Professional for “Silverlight” Technology for year 2009-2010.


I am very much thankful to all my readers who encourage me time to time to explore new avenues of technologies especially Microsoft Technologies. Also I am happy to become MVP for this year again, My ASP.NET MVP last year got renew up. I am also very much thankful for people in community for their valuable feedback and encouragement given in offline events. It was great experience for me to present for two days on Silverlight 2 & 3 in Tech.Ed 09 India and followed by Tech.Ed 09 on the Road events.

I am very much thankful to Abhishek Kant (MVP Lead for India), Abhishek Baxi (Microsoft), Mahesh Mitkari (Microsoft MVP from Pune), Dhaval Faria (Microsoft MVP from Mumbai), Suprotim Agarwal (Microsoft MVP and founder of and all my friends from Pune and Pune User Group.

I am also thankful to Mahesh Sabnis (MCT) who helped me in my 2-3 articles in WCF part of it. He help me a lot to learn WCF and WPF. Rather I learn .NET from him :)

Microsoft MVP : What ? Why to become? How to become ?

At community events, we always do our best to inform and update you and make you aware of Microsoft MVP Program, However I got many mails and Tweets which shows some common questions in community about MVP Program.

Many of my friends think that I given few certification exams to get MVP, well..friends, let me wipe out basic confusion :

Microsoft MVP is award and not Certification !! :)

So..what are you waiting for..Check out following links and join the most happening group of Microsoft professionals all over the world..shortly MVPs !!

For my friends in India and South Asia :


For my friends who are at various parts of the world :

I will however keep touching upon ASP.NET, Dynamic Data, .NET Framework, Visual Studio and other tools along with Silverlight 2, 3, LOB applications, RIA Services, Expression Studio etc. in coming days at this place. Also you can meet me at Offline events which are conducted by local Microsoft user group for Pune as Pune User Group. Soon, I will be updating my blog with Twitter feeds etc. so keep checking this place as you doing it for past few months.

Thanks once again ! :)