Solved

Using System.Diagnostics.PerformanceCounter in Silverlight

Posted on 2009-05-07
2
1,151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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