如何设置程序的CPU亲和力? [英] how to set CPU affinity of a program?

查看:121
本文介绍了如何设置程序的CPU亲和力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#编写的程序,我正在使用VSTS 2008 + .Net 3.5 + Windows Vista Enterprise x86开发Windows Forms应用程序.

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.

我当前的计算机是双核CPU,我想将程序的CPU亲和力设置为在特定CPU上运行,并释放另一个CPU来执行其他工作.任何想法如何做到这一点?通过编码或配置都可以.

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.

更多背景是,我的程序占用大量CPU,因此我不想让它占用计算机上的所有两个CPU资源,而是想释放一个CPU,以便可以快速同时浏览网络.:-)

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

先谢谢了,乔治

推荐答案

  1. 转到任务管理器-> 进程标签.
  2. 寻找您的程序.右键单击它.
  3. 选择设置亲和力,然后取消选中其中一个复选框.
  1. Go to Task Manager -> Processes tab.
  2. Look for your program. Right click on it.
  3. Select Set Affinity and uncheck one of the checkboxes.

这应该为您释放一个处理器.

This should free up one processor for you.

要从代码中执行此操作,可以添加以下语句:

For doing it from the code you can add this statement:

System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr) 1;

干杯!

这篇关于如何设置程序的CPU亲和力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆