如何设置程序的CPU亲和力?
我有一个用 C# 编写的程序,我使用 VSTS 2008 + .Net 3.5 + Windows Vista Enterprise x86 来开发 Windows 窗体应用程序。
我当前的计算机是双核CPU,我想将程序的CPU亲和力设置为在特定CPU上运行,并释放另一个CPU来执行其他工作。 有什么想法如何做到这一点? 通过编码或配置都可以。
多一点背景是,我的程序是CPU密集型的,所以我不想让它占用我计算机上的所有两个CPU资源,我想释放一个CPU,以便我可以同时快速浏览网络。 :-)
提前致谢, 乔治
I have a program written in C#, I am using VSTS 2008 + .Net 3.5 + Windows Vista Enterprise x86 to develop a Windows Forms application.
My current computer is dual-core CPU, I want to set CPU affinity of my program to run on a specific CPU and free another CPU to do some other job. Any ideas how to do this? Either through coding or configuration is ok.
A little more background is, my program is CPU intensive, so I do not want to let it occupy all two CPU resources on my computer and I want to free one CPU so that I can browse network at the same time quickly. :-)
thanks in advance,
George
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
执行此操作的 Windows API 函数为 SetProcessAffinityMask() 和 SetThreadAffinityMask( )。 我不了解.NET,所以我不能说这些函数是否有包装器,但是 这似乎表明并非如此。
顺便说一句:我同意这些仅在非常特殊的情况下才是必要的,通常最好让操作系统调度程序来处理它。 如果你必须问如何做,那么这是你可能不应该做的问题之一。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这应该可以为您释放一个处理器。
要从代码中执行此操作,您可以添加以下语句:
干杯!
This should free up one processor for you.
For doing it from the code you can add this statement:
Cheers!