如何启动低优先级的进程?C# [英] How do I launch a process with low priority? C#
问题描述
我想执行一个命令行工具来处理数据.它不需要阻塞.我希望它是低优先级的.所以我写了下面的
I want to execute a command 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 message "No process is associated with this object." Why? How do I properly launch this app in low priority?
没有该行 app.PriorityClass = ProcessPriorityClass.BelowNormal;
应用程序运行良好.
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屋!