Solved

Using System.Diagnostics.PerformanceCounter in Silverlight

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Enable Clear Text in Win 8.1 7 47
How to deal with "Consider using Code First Migrations to update the database" ? 7 395
WPF issue with Trigger 2 130
windbg taking it's time 32 101
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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