2

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.

Ethan
  • 565
  • 1
  • 7
  • 17

2 Answers2

1

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.

Shekhar_Pro
  • 18,056
  • 9
  • 55
  • 79
  • This is nice, but it only gives me an average load over all cores. It would be nice to have the load for each core. Also, I don't see any way to get free/total memory. – Ethan Feb 13 '11 at 04:31
  • Sorry but from silverlight this is as far as we can go.. for RAM and Processor count you will need to do have somthing installed on the client side itself to tell you.. from browser you can't. – Shekhar_Pro Feb 13 '11 at 04:39
1

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();
    }
}
Vladimir Salin
  • 2,951
  • 2
  • 36
  • 49
  • This should probably be a comment on Shekhar's answer. – thegrinner Jul 12 '11 at 03:12
  • Or at least summarize how you could achieve the OP's goal using code from that article: http://meta.stackexchange.com/questions/13369/is-it-okay-to-answer-a-stackoverflow-question-with-a-link – Nanne Jul 12 '11 at 07:51
  • Yes, surely, it should be posted as a comment on previous answer, but I haven't found button "add comment". – Vladimir Salin Jul 12 '11 at 09:00
  • Ah, I apologize, I didn't notice you had too little rep to post [comments](http://stackoverflow.com/privileges/comment). My bad. – thegrinner Jul 12 '11 at 14:33