Solved

Using System.Diagnostics.PerformanceCounter in Silverlight

Posted on 2009-05-07
2
1,132 Views
Last Modified: 2013-11-12
Hi,

I have a silverlight guage which is a 360 dial and in my page.xaml.vb file i setup a Dispatchtimer which calls a function every 1 second .. this updates the dial's value property and that is working fine...

Now i want to pass the cpu usage value to the dial  (im trying to create a server dashboard)...
Now - on a normal webpage i managed to get the cpu usage displayed using the code below.

Note that when i copy this code into the page.xaml.vb file ...  i get a msg "Type PerformanceCounter is not defined"

How would I do this?
Imports System.Diagnostics
 

...
 

Private m_Performance As PerformanceCounter = New PerformanceCounter("Processor", "% Processor Time", "_Total")
 

        MsgBox(Me.m_Performance.NextValue().ToString)

        Threading.Thread.Sleep(300)

        MsgBox(Me.m_Performance.NextValue().ToString)

        Threading.Thread.Sleep(300)

        MsgBox(Me.m_Performance.NextValue().ToString)

        Threading.Thread.Sleep(300)

Open in new window

0
Comment
Question by:PierreBeukes
2 Comments
 
LVL 1

Accepted Solution

by:
aweilee earned 500 total points
ID: 24326587
This code doesn't work because you cannot access performance counters from your Silverlight application. Anyway, even if you could, remember that Silverlight code is running on the client side, not server side like ASP.NET so you would get the CPU usage on the client machine, not on the server. Not what you want, right?

So what do you need to do? Create a simple Web Service (or WCF service) on the ASP.NET Server, and place your above code inside. Call it from your Silverlight application and place the result inside your gauge. Done.
0
 
LVL 3

Author Comment

by:PierreBeukes
ID: 24334673
aaah yes ... it runs on client - my bad :)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video discusses moving either the default database or any database to a new volume.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now