Determining CPU and RAM usage in a Silverlight 4 WIndows Sidebar Gadget

1.7k Views Asked by At

I'm trying to write a Silverlight 4 Windows Sidebar Gadget that, among other things, can monitor the usage of each CPU core (as a percentage) and the usage of RAM (in bytes) of the host computer. I've tried using System.Management, but Visual Studio won't let me add it, as it's not part of Silverlight.

In the end, I'm looking for some method that simply returns the usage of a specific CPU core. Automatically detecting the number of cores would be a bonus. The same goes for RAM.

Extensive searching has led me to believe that this is possible through COM+ automation, but I'm clueless as to how. Any direction would be very much appreciated.

2

There are 2 best solutions below

2
On

You can use System.Windows.Analytics class to get systems stats..

It has a AverageProcessorLoad which you can use to get the current CPU usage(Value between 0 and 1) .And its for Silverlight only.

You can simply use it like this:

float averageCPUUsage = System.Windows.Analytics.AverageProcessorLoad; 
float myAppCPUUsage = System.Windows.Analytics.AverageProcessLoad;// Get cpu usage by your current app.

Update

But from Silverlight this is as far as we can go.. for RAM and Processor count you will need to have somthing installed on the client side itself to tell you.. from browser you can't.

4
On

You can also take a look at sample of System.Windows.Analytics usage on this article.

A little fragment of code from that article that shows usage of System.Windows.Analytics:

public partial class Page : UserControl 
{ 
    Analytics analytics;

    public Page() 
    { 
        InitializeComponent(); 
        CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);            
    }

    void CompositionTarget_Rendering(object sender, EventArgs e) 
    { 
        if (analytics == null) 
            analytics = new Analytics();
    }
}