How to set priority of another application in c#

1.9k views Asked by At

How should I set the priority of a different application running on the computer in c# win form. I'm a little new to this website and coding all together.

System.Diagnostics.Process.Start("cmd.exe","wmic process where name=\"HD-Frontend.exe\" CALL setpriority 32");

Is what I've tried so far. Just didn't work... :(

1

There are 1 answers

4
Eric On BEST ANSWER

setpriority 32 appears to be a linux call

What you need to do is get the Process handle from Start like this

Process myProcess = Process.Start("cmd.exe", "wmic process where name=\"HD-Frontend.exe\"");

Then play with the priority once you have the handle

myProcess.PriorityClass = RealTime;

Alternatively, you could define your process before starting it and edit the priority before it has started

myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.PriorityClass = RealTime;
myProcess.Start();

Look at the ProcessPriority property of Process