Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My application is hosted on 5-6 servers, I need to develop a window service which will run on my machine and will give me a alert if CPU utilization gets more than some set limit for more than 30 min.

I got a sample code through which I can get the result but for this I need to host this service on each machine which I dont want.

public int getCPUCounter()

       PerformanceCounter cpuCounter = new PerformanceCounter();
       cpuCounter.CategoryName = "Processor";
       cpuCounter.CounterName = "% Processor Time";
       cpuCounter.InstanceName = "_Total";

       // will always start at 0
       dynamic firstValue = cpuCounter.NextValue();
       // now matches task manager reading
       dynamic secondValue = cpuCounter.NextValue();

       return secondValue;


Thanks in advance
Updated 17-Feb-15 22:12pm
StM0n 18-Feb-15 4:48am    
Mhm... have you tried WMI, like
suhel_khan 19-Feb-15 1:12am    
I tried this but no luck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900