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_927308.html
However, the PerformanceCounter class is not included in the .NET Compact Framework 3.5.
Are there other ways?
Thanks :)
You need to sum thread process times for processes and then you get a list of processes and the time they run within a time period: http://www.hjgode.de/wp/2012/12/14/mobile-development-a-remote-cpu-monitor-and-cpu-usage-analysis/
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 a mix of the Toolhelp APIs and
GetThreadTimes
, but it's very heavy handed and the process of calculating it uses a lot of CPU all by itself. Generally speaking getting CPU usage isn't worth the expense of the code or the execution time required to get it.