Calculating process CPU usage

Recently, I needed a routine to calculate CPU usage so that I could detect when a process went idle. As usual a quick search on Google Groups turned up the answer in this post. The routine calls GetProcessTimes then sleeps for a brief period, calls it again and calculates the average over that interval. The only change I made was to take into account the number of CPU’s on the system by calling GetSystemInfo and divide accordingly.