我怎样才能获得“可用”的计数?我的应用程序的处理器?
我知道如何获取计算机上的物理处理器数量和逻辑处理器数量,但我想知道我的应用程序可以访问多少个逻辑处理器。
例如,我在四核机器上进行开发,但我有许多单核用户,并且在许多情况下我“简化”了界面,或者遇到了多核系统从未遇到过的锁定问题。
因此,为此,我设置了 VSTS 以在调试或“调试单核”中构建我的应用程序。目标基本上是将处理器亲和力设置为核心“0”,通过查看 Windows 任务管理器是否按预期工作。
我的问题是,我刚刚注意到(事后看来这应该是显而易见的),在我的整个代码中,我有 Environment.ProcessorCount >= some
,这对于真正的单核机器非常有用,但没有让我了解我的单个“逻辑上可用的核心”。
如何获取“可用”逻辑核心的数量?
C# 优先
I know how to get the number of physical, and number of logical processors on my machine, but I want to know how many logical processors my application has access to.
For instance, I develop on a quad core machine, but I have a number of single core users out there, and in many instances I "dumb down" the interface, or run into locking problems that a multi-core system never experiences.
So, to that end I have set up VSTS to build my app in either debug or "Debug Single Core". The goal there is basically to set the processor affinity to core "0", which by looking at the windows task manager is working as expected.
My problem is, I just noticed, ( and hind sight says it should have been obvious ), that throughout my code I have Environment.ProcessorCount >= something
, which works great for truly single core machines, but doesn't give me a read on my single "logically available core".
How can I get the number of "available" logical cores?
C# preferred
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
特别感谢Jesse Slicer找到的答案此处。
虽然不是所问问题的公认答案,但这是我正在寻找的答案。
这基本上是我根据杰西的回答得到的结果。
A special thanks goes out to Jesse Slicer's answer found here.
Although not the accepted answer to the question asked, it IS the answer I am looking for.
Here is basicly what I ended up with based on Jesse's answer.