获取设备的CPU利用率,可用RAM的WinCE在C#利用率、设备、WinCE、CPU

2023-09-03 06:42:52 作者:脸红馆

我在寻找获得总的CPU使用率和可用RAM的设备上在C#中量的替代办法。

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

这里有描述一个非常简单的解决方案: http://zamov.online .FR / EXHTML / CSHARP / CSHARP%5F927308.html

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

不过,PerformanceCounter类不包含在.NET Compact Framework 3.5的。

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

有没有其他办法?

感谢:)

推荐答案

可用RAM是相当容易的 - 尽管你有物理和虚拟抗衡 - 无一不是重要的。您的P / Invoke GlobalMemoryStatus 为(像往常一样自卫队拥有它已经包裹在一个更友好的对象模型以及)。

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使用率是不同的动物完全。在PC上,你有一个很好的寄存器,让您轻松,廉价获得CPU的使用情况。在ARM(这是在你的WinMo设备)你没有这一点。它可以使用 TOOLHELP的API 的组合和的 GetThreadTimes ,但它是非常重手,计算它使用了大量的CPU全部由自己的过程。一般来说让CPU使用率是不值得牺牲的code或得到它所需的执行时间。

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.