Process.PriorityClass Property
Gets or sets the overall priority category for the associated process.
[Visual Basic] Public Property PriorityClass As ProcessPriorityClass [C#] public ProcessPriorityClass PriorityClass {get; set;} [C++] public: __property ProcessPriorityClass get_PriorityClass(); public: __property void set_PriorityClass(ProcessPriorityClass); [JScript] public function get PriorityClass() : ProcessPriorityClass; public function set PriorityClass(ProcessPriorityClass);
Property Value
The priority category for the associated process, from which the BasePriority of the process is calculated.
Exceptions
| Exception Type | Condition |
|---|---|
| Win32Exception | Process priority information could not be set or retrieved from the associated process resource.
-or- The process identifier or process handle is zero. (The process has not been started.) |
| SystemException | You are attempting to access the PriorityClass property for a process that is running on a remote computer. The property is available only for processes running on the local computer.
-or- The process Id was not available. |
| PlatformNotSupportedException | You have set the PriorityClass to AboveNormal or BelowNormal when using Windows 98. These platforms do not support those values for the priority class. |
Remarks
A process priority class encompasses a range of thread priority levels. Threads with different priorities that are running in the process run relative to the priority class of the process. Win32 uses four priority classes with seven base priority levels per class. These process priority classes are captured in the ProcessPriorityClass enumeration, which lets you set the process priority to Idle, Normal, High, High, BelowNormal, or RealTime. Based on the time elapsed or other boosts, the base priority level can be changed by the operating system when a process needs to be put ahead of others for access to the processor. In addition, you can set the PriorityBoostEnabled to temporarily boost the priority level of threads that have been taken out of the wait state. The priority is reset when the process returns to the wait state.
The BasePriority property lets you view the starting priority that is assigned to a process. However, because it is read-only, you cannot use the BasePriority property to set the priority of a process. To change the priority, use the PriorityClass property, which gets or sets the overall priority category for the process.
The priority class cannot be viewed using System Monitor. The following table shows the relationship between the BasePriority and PriorityClass values.
Windows 98 Platform Note: Setting the priority class to AboveNormal or BelowNormal causes an exception to be thrown.
Example
[Visual Basic, C#, C++] The following example starts an instance of Notepad. The example then retrieves and displays various properties of the associated process. The example detects when the process exits, and displays the process's exit code.
[Visual Basic] Imports System Imports System.Diagnostics Imports System.Threading Namespace Process_Sample Class MyProcessClass Public Shared Sub Main() Try Dim myProcess As Process myProcess = Process.Start("NotePad.exe") While Not myProcess.HasExited Console.WriteLine() ' Get physical memory usage of the associated process. Console.WriteLine("Process's physical memory usage: " + _ myProcess.WorkingSet.ToString) ' Get base priority of the associated process. Console.WriteLine("Base priority of the associated process: " + _ myProcess.BasePriority.ToString) ' Get priority class of the associated process. Console.WriteLine("Priority class of the associated process: " + _ myProcess.PriorityClass.ToString) ' Get user processor time for this process. Console.WriteLine("User Processor Time: " + _ myProcess.UserProcessorTime.ToString) ' Get privileged processor time for this process. Console.WriteLine("Privileged Processor Time: " + _ myProcess.PrivilegedProcessorTime.ToString) ' Get total processor time for this process. Console.WriteLine("Total Processor Time: " + _ myProcess.TotalProcessorTime.ToString) ' Invoke overloaded ToString function. Console.WriteLine("Process's Name: " + myProcess.ToString) Console.WriteLine("-------------------------------------") If myProcess.Responding Then Console.WriteLine("Status: Responding to user interface") myProcess.Refresh() Else Console.WriteLine("Status: Not Responding") End If Thread.Sleep(1000) End While Console.WriteLine() Console.WriteLine("Process exit code: {0}", myProcess.ExitCode) Catch e As Exception Console.WriteLine("The following exception was raised: " + e.Message) End Try End Sub 'Main End Class 'MyProcessClass End Namespace 'Process_Sample [C#] using System; using System.Diagnostics; using System.Threading; namespace Process_Sample { class MyProcessClass { public static void Main() { try { Process myProcess; myProcess = Process.Start("NotePad.exe"); while(!myProcess.HasExited) { Console.WriteLine(); // Get physical memory usage of the associated process. Console.WriteLine("Process's physical memory usage: " + myProcess.WorkingSet); // Get base priority of the associated process. Console.WriteLine("Base priority of the associated process: " + myProcess.BasePriority); // Get priority class of the associated process. Console.WriteLine("Priority class of the associated process: " + myProcess.PriorityClass); // Get user processor time for this process. Console.WriteLine("User Processor Time: " + myProcess.UserProcessorTime); // Get privileged processor time for this process. Console.WriteLine("Privileged Processor Time: " + myProcess.PrivilegedProcessorTime); // Get total processor time for this process. Console.WriteLine("Total Processor Time: " + myProcess.TotalProcessorTime); // Invoke overloaded ToString function. Console.WriteLine("Process's Name: " + myProcess.ToString()); Console.WriteLine("-------------------------------------"); if(myProcess.Responding) { Console.WriteLine("Status: Responding to user interface"); myProcess.Refresh(); } else { Console.WriteLine("Status: Not Responding"); } Thread.Sleep(1000); } Console.WriteLine(); Console.WriteLine("Process exit code: {0}", myProcess.ExitCode); } catch(Exception e) { Console.WriteLine("The following exception was raised: " + e.Message); } } } } [C++] #using <mscorlib.dll> #using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::Threading; int main() { try { Process* myProcess; myProcess = Process::Start(S"NotePad.exe"); while(!myProcess->HasExited) { Console::WriteLine(); // Get physical memory usage of the associated process. Console::WriteLine(S"Process's physical memory usage: {0}", myProcess->WorkingSet.ToString()); // Get base priority of the associated process. Console::WriteLine(S"Base priority of the associated process: {0}", myProcess->BasePriority.ToString()); // Get priority class of the associated process. Console::WriteLine("Priority class of the associated process: {0}", __box(myProcess->PriorityClass)); // Get user processor time for this process. Console::WriteLine(S"User Processor Time: {0}", myProcess->UserProcessorTime.ToString()); // Get privileged processor time for this process. Console::WriteLine(S"Privileged Processor Time: {0}", myProcess->PrivilegedProcessorTime.ToString()); // Get total processor time for this process. Console::WriteLine(S"Total Processor Time: {0}", myProcess->TotalProcessorTime.ToString()); // Invoke overloaded ToString function. Console::WriteLine(S"Process's Name: {0}", myProcess->ToString()); Console::WriteLine(S"-------------------------------------"); if (myProcess->Responding) { Console::WriteLine(S"Status: Responding to user interface"); myProcess->Refresh(); } else { Console::WriteLine(S"Status: Not Responding"); } Thread::Sleep(1000); } Console::WriteLine(); Console::WriteLine("Process exit code: {0}", myProcess->ExitCode.ToString()); } catch (Exception* e) { Console::WriteLine(S"The following exception was raised: {0}", e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- SecurityPermission for calling any members of System.Diagnostic.Process with full trust. Associated enumeration: PermissionState.Unrestricted
See Also
Process Class | Process Members | System.Diagnostics Namespace | BasePriority | PriorityBoostEnabled