您可以限制.NET Process Object上的CPU使用率吗? [英] Can you limit the CPU usage on a .NET Process Object?

查看:41
本文介绍了您可以限制.NET Process Object上的CPU使用率吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的应用程序启动了用C编写的组件.

An application I'm contributing to fires up a component written in C.

C进程进行了大量繁琐的工作,如果您不小心,可能会严重影响您的CPU.

The C process does some pretty heavy crunching and if your not careful can really hammer your CPU.

是否可以为.NET产生的外部进程设置限制?

Is there a way to set a limit to external processes spawned by .NET?

我已经看到

I've seen this artivcle on setting a hard memory limit at the OS level, is there a similar thing for CPU?

推荐答案

不在Windows中.但是,您可以降低进程优先级,这将减少有问题的进程在CPU上进行调度并干扰其他(可能是更高优先级)应用程序的可能性.例如,来自

Not in Windows. You can lower the process priority though, which will reduce the likelihood that the problematic process will be scheduled on the CPU and interfere with other (presumably higher priority) applications. For instance, from http://dotnet-concepts-queries-interviews.blogspot.com/2007/05/how-to-set-process-priority-in-net.html:

Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;

请记住,如果包装盒上没有其他东西在运行,则可能想要消耗所有可用的CPU.

Keep in mind, if you don't have anything else running on the box, you probably want this process to consume all of the available CPU.

如果它在多处理器盒上,则还可以设置CPU亲和力,将处理限制在某些内核上,而将其他内核留给其他应用程序使用.通常,操作系统通常会很好地安排应用程序线程,因此设置进程优先级可能会带来更好的总体效果.请参见如何在.NET中设置处理器亲和力?

You can also set the CPU affinity if it is on a multi-processor box, limiting the processing to certain cores and leaving others free for other applications. Generally the OS does a good job of scheduling application threads though, so setting the process priority is likely to have a better overall result. See How Can I Set Processor Affinity in .NET?

这篇关于您可以限制.NET Process Object上的CPU使用率吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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