![Download the movie bloodshot](https://cdn2.cdnme.se/5447227/9-3/8_64e61dfb9606ee7f6adf5896.png)
![monitor cpu usage windows 10 monitor cpu usage windows 10](https://www.winxdvd.com/seo-img/play-video/high-cpu-usage.jpg)
refresh delay 1.5 seconds int RefreshInterval = 1500 I know it sounds complicated, the following code will explain it better: the managed way - using the System.Diagnostics namespaceĪfter we get this value, we keep it for the next run (the refresh time is usually 1.5 seconds), we then decrease the new value from the old value and divide it by the refresh time.the API way - using the GetSystemTimes() function.CPU Usage Calculation Conceptįor calculating the CPU usage of processes, we need to get a value that indicates for how much time they have used the processor in a certain period of time, this value is equal to the sum of the time that the kernel and the user have spent on these processes, I will demonstrate two ways to achieve this value: I tried it and it's a good method as long as you use only a few (1-3) PerformanceCounters because it consumes a lot of CPU which got me to a usage of 6% - 18% for my own Task Manager for just the refresh operation every 2 seconds. I searched the web for methods of getting the CPU usage but the best I could find was only advices for using PerformanceCounter("Processor","% Process Time",ProcessName) for monitoring the usage value. My journey began when I had to write a Task Manager look alike that also had some netstat features. Download demo project (.NET 2.0) - 13.6 KB.
![Download the movie bloodshot](https://cdn2.cdnme.se/5447227/9-3/8_64e61dfb9606ee7f6adf5896.png)