March 10, 2011, 10:16 p.m.
posted by bert
Boosting the Priority of a Process Programmatically
You want a specific program to run at a higher priority than most of the other processes on the machine to help it complete a time-critical task.
// Run recursive dir operation on the c:\ drive ProcessStartInfo psi = new ProcessStartInfo("cmd.exe","/C\"dir c:\\ /S\""); // Don't show the window. psi.CreateNoWindow = true; // Start the process. Process p = Process.Start(psi); // Raise the process priority to AboveNormal. p.PriorityClass = ProcessPriorityClass.AboveNormal;
The Process.PriorityClass property takes one of the ProcessPriorityClass enumeration values to indicate what priority the process should have. The enumeration values and descriptions are listed in Figure.
Setting the priority above AboveNormal should be done in only very specialized situations for short durations of time, as it can starve other processes on the machine. The operating system uses the priority level to determine scheduling for the processors, and if one process is set to a higher priority for a long time, the processes with lesser priority may never finish.
See the "Process Class," "ProcessStartInfo Class," and "ProcessPriorityClass Enumeration" topics in the MSDN documentation.