Getting the device's CPU utilization and free RAM on WinCE in C#

一世执手 提交于 2019-12-31 02:56:05

问题


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 :)


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/1609996/getting-the-devices-cpu-utilization-and-free-ram-on-wince-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!