Friday, 23 August 2013

get current cpu utilization in c#

get current cpu utilization in c#

I want to have current CPU utilization in my project
namespace Monitoring_Tool
{
public partial class ajaxExecute : System.Web.UI.Page
{
private PerformanceCounter theCPUCounter = new
PerformanceCounter("Processor", "% Processor Time", "_Total");
private PerformanceCounter theMemCounter = new
PerformanceCounter("Memory", "Available MBytes");
protected void Page_Load(object sender, EventArgs e)
{
float cpuUsage = 0.00F;
cpuUsage = this.theCPUCounter.NextValue();
}
}
}
When i debug my project value in cpuUsage is showing 0.00 but when i do
QuickWatch On this.theCPUCounter.NextValue(); it is showing 20.6786852
Why cant i store it in variable ?

No comments:

Post a Comment