• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1166
  • Last Modified:

Using System.Diagnostics.PerformanceCounter in Silverlight

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
PierreBeukes
Asked:
PierreBeukes
1 Solution
 
aweileeCommented:
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
 
PierreBeukesAuthor Commented:
aaah yes ... it runs on client - my bad :)
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now