Solved

Using System.Diagnostics.PerformanceCounter in Silverlight

Posted on 2009-05-07
2
1,141 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 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