Geeks With Blogs

@Sorskoot
  • Sorskoot "Visual Studio 2013, will be available later this year, with a preview build publicly available at Build" http://t.co/SV28646Qr6 about 482 days ago

News


Timmy Kokke's Blog

↑ Grab this Headline Animator

Timmy Kokke at Blogged
Timmy Kokke …just sorting my bubbles…

silverbullet I’d like to provide you with a SilverBullet™, a small snippet of Silverlight, a class or namespace hidden in the silverlight .NET framework, to help you out in times of need. It’s not to learn, but something to keep in your pocket. Just remember it’s there and you’re safe.

When developing applications, especially graphic intensive web applications you want to monitor the performance when running. The System.Windows.Analytics class can help you with that.

The class has no methods of any significance and only three read-only properties:

  • AverageProcessLoad – shows the average of all cores on how much of the CPU the process is using

 

 

 

Using these properties is very simple as this example will show:

This example uses a timer to display and update the values from the properties in the System.Windows.Analytics class.

To display the various values added a couple of text boxes and a listbox to stackpanel. Too keep things simple for this example, just add the stackpanel to MainPage.xaml in a new silverlight project.

<StackPanel x:Name="LayoutRoot" Orientation="Vertical">
    <TextBlock x:Name="AverageProcessLoad" />
    <TextBlock x:Name="AverageProcessorLoad" />
    <ListBox x:Name="GpuInfo" />
    <TextBlock x:Name="Time"/>
</StackPanel>

 

 

Next, add the following to the codebehind, MainPage.xaml.cs

 public MainPage()
        {            
            InitializeComponent();
            var t = new DispatcherTimer();
            t.Tick += TickHandler;
            t.Interval = new TimeSpan(0,0,1);
            t.Start();
        }
 
        void TickHandler(object sender, EventArgs e)
        {
            Time.Text = DateTime.Now.ToLongDateString()+ " -- "+ 
                            DateTime.Now.ToLongTimeString();           
            var an = new Analytics();
 
            AverageProcessLoad.Text = 
                an.AverageProcessLoad.ToString();
            AverageProcessorLoad.Text = 
                an.AverageProcessorLoad.ToString();
 
            GpuInfo.Items.Clear();
            foreach (var gpuInformation in an.GpuCollection)
            {
                GpuInfo.Items.Add(string.Format(
                    "ID:{0}, Version:{1}, vendorId{2} ", 
                    gpuInformation.DeviceId,
                    gpuInformation.DriverVersion,
                    gpuInformation.VendorId)
                );
            }
        }

 



 
Shout it
Tags van Technorati:
dotNed blogger
kick it on DotNetKicks.com
Posted on Thursday, September 3, 2009 5:27 PM Silverlight , SilverBullet , dotnetmag , CodeProject | Back to top


Comments on this post: SilverBullet #9 - System.Windows.Analytics

# re: SilverBullet #9 - System.Windows.Analytics
Requesting Gravatar...
keep em coming and nice work.
Left by bill moore (codenenterp) on Oct 26, 2009 8:03 PM

Your comment:
 (will show your gravatar)
 


Copyright © Timmy Kokke | Powered by: GeeksWithBlogs.net | Join free