How do I launch a process with low priority? C#

筅森魡賤 提交于 2019-12-03 09:25:21

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.

You can create a process with lower priority by doing a little hack. You lower the parent process priority, create the new process and then revert back to the original process priority:

var parent   = Process.GetCurrentProcess();
var original = parent.PriorityClass;

parent.PriorityClass = ProcessPriorityClass.Idle;
var child            = Process.Start("cmd.exe");
parent.PriorityClass = original;

child will have the Idle process priority right at the start.

If you're prepared to P/Invoke to CreateProcess, you can pass CREATE_SUSPENDED in the flags. Then you can tweak the process priority before resuming the process.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!