CPU usage in .net core (at least on Windows)

我是研究僧i 提交于 2019-12-06 20:22:20

问题


So PerformanceCounter is gone in dotnet core. I understand it was because it was not Linux-compatible.

This comment here: ( What is the story of Performance Counters for .NET Core? ) seems to suggest that if I was willing to run it only on Windows I could "make use of Windows-specific features", but I don't know how I could integrate that in dotnet core.

The reason I am willing to do this workaround is to keep the dotnet core codebase so I don't have to migrate once there is a cross-platform solution for PerformanceCounter.

So to summarize my question: how can I run the CPU usage in dotnet core when running on Windows?


Other relevant posts that I've found:

  • This solution seems to suggest that Process.GetCurrentProcess() would be enough, which I don't quite understand (PerformanceCounterprovided the full CPU usage for the machine).

  • Looping through all processes (as this other post seem to suggest?) is not feasible (it throws an exception for some processes) and it looks pretty slow as well which is a problem for my use case.

来源:https://stackoverflow.com/questions/45675734/cpu-usage-in-net-core-at-least-on-windows

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