Sunday, May 13, 2007

How to set process priority in .NET?

Here is the sample code lines,
which allows setting the priority of the process.

The process here, refers to WinForms application or Windows Service which can be seen in Task Explorer being executed as an EXE.

Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;


Namespace: System.Diagnostics
Class: System.Diagnostics.Process
Method: System.Diagnostics.Process.GetCurrentProcess()
--> This method allows us to get instance of the process under which the application is executed.
Property: PriorityClass
--> This property allows us to get or set the process priority

Enumerator: ProcessPriorityClass
--> This enumerator contains values as RealTime, High, AboveNormal, Normal, BelowNormal, Low. These are the same process priority levels as can be seen from Task Explorer for any windows processes.

No comments:

 
Dotster Domain Registration Special Offer