
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Boosting the Priority of a Process Programmatically
|
483
See Also
See the “AppDomainSetup class,” “AppDomainSetup.ApplicationTrust Property,”
and “AppDomainSetup.ActivationArguments Property” topics in the MSDN
documentation.
8.17 Boosting the Priority of a Process
Programmatically
Problem
You want a specific program to run at a higher priority than most of the other pro-
cesses on the machine to help it complete a time-critical task.
Solution
Use the ProcessStartInfo and Process classes to launch the program and then adjust
it to a higher priority like this:
// 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;
Discussion
The Process.PriorityClass property takes one of the ProcessPriorityClass enumer-
ation values to indicate what priority the process should have. The enumeration val-
ues and descriptions are listed in Table 8-5.
Table 8-5. ProcessPriorityClass enumeration values
Name Description
Idle Run only when the system is idle. Preempted by any action.
BelowNormal Will run with a light load on the CPU but will be preempted ...