Monday, May 02, 2005

The Code Project - How to get CPU usage of processes and threads - C# Programming

The Code Project - How to get CPU usage of processes and threads - C# Programming: "Introduction

The CPU usage is often recognized from Windows Task Manager. I will explain in this article the most efficient way I could find to calculate it for both processes and threads.
Background

My journey began when I wanted to write a Task Manager look alike that also had some netstat features. 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. I tried it and it's a good method as long as you use only few (1-3) PerformanceCounters because it consumes a lot of CPU itself which got me to a usage of 6% - 18% for my own task manager for just the refresh operation every 2 seconds."

No comments: