我该如何推出具有低优先级的进程? C# [英] How do I launch a process with low priority? C#
问题描述
我要执行一个cmd行工具来处理数据。它并不需要被阻断。
我希望它是低优先级。所以我写了下面的
I want to execute a cmd line tool to process data. It does not need to be blocking. I want it to be low priority. So I wrote the below
Process app = new Process();
app.StartInfo.FileName = @"bin\convert.exe";
app.StartInfo.Arguments = TheArgs;
app.PriorityClass = ProcessPriorityClass.BelowNormal;
app.Start();
不过,我得到的味精System.InvalidOperationException没有过程与此对象关联。为什么? ?如何正确使用此应用在低优先级
However, I get a System.InvalidOperationException with the msg "No process is associated with this object." Why? How do I properly launch this app in low priority?
PS:如果没有行app.PriorityClass = ProcessPriorityClass.BelowNormal;该应用程序运行正常。
PS: Without the line app.PriorityClass = ProcessPriorityClass.BelowNormal; the app runs fine.
推荐答案
尝试设置的priorityClass在启动的过程。任务管理器以这种方式工作,让您在一个已经运行的进程设置优先级。
Try setting the PriorityClass AFTER you start the process. Task Manager works this way, allowing you to set priority on a process that is already running.
这篇关于我该如何推出具有低优先级的进程? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!