Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I lower the priority of a process?

You can change the scheduling priority of a running process to a value lower or higher than the base scheduling priority by using the renice command from the command line. This command changes the nice value of a process.

What happens if I set priority to low?

If you set priority to low, it will only run, when nothing else with higher priority is running, resulting in more responsive GUI. Generally programs that should have this tweaked such as video editing apps (VirtualDub) or renderers offer this.


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.