views:

495

answers:

1

I'm looking for alternative ways of obtaining the total CPU utilization percentage and the amount of free RAM on the device in C#.

There is an extremely easy solution described here: http://zamov.online.fr/EXHTML/CSharp/CSharp%5F927308.html

However, the PerformanceCounter class is not included in the .NET Compact Framework 3.5.

Are there other ways?

Thanks :)

+2  A: 

Free RAM is fairly easy - though you have both Physical and Virtual to contend with - and both are important. You P/Invoke GlobalMemoryStatus for that (as usual the SDF has it already wrapped in a more friendly object model as well).

CPU usage is a different animal altogether. On the PC you have a nice processor register that gives you easy, cheap access to the CPU usage. On ARM (which is what's in your WinMo device) you don't have that. It can be calculated using the toolhelp APIs getting thread times, but it's very heavy handed and the process of calculating it uses a lot of CPU all by itself. Generally speaking getting SPU usage isn't worth the expense of the code or the execution time required to get it.

ctacke