Process.PriorityClass Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta la categoria di priorità complessiva per il processo associato.
public:
property System::Diagnostics::ProcessPriorityClass PriorityClass { System::Diagnostics::ProcessPriorityClass get(); void set(System::Diagnostics::ProcessPriorityClass value); };
public System.Diagnostics.ProcessPriorityClass PriorityClass { get; set; }
member this.PriorityClass : System.Diagnostics.ProcessPriorityClass with get, set
Public Property PriorityClass As ProcessPriorityClass
Valore della proprietà
Categoria di priorità per il processo associato, da cui viene calcolato l'oggetto BasePriority del processo.
Eccezioni
Impossibile impostare o recuperare informazioni sulla priorità del processo dalla risorsa di processo associata.
oppure
L'identificatore del processo o l'handle di processo è zero. Il processo non è stato avviato.
Si sta tentando di accedere alla PriorityClass proprietà per un processo in esecuzione in un computer remoto. Questa proprietà è disponibile solo per i processi in esecuzione nel computer locale.
Il processo Id non è disponibile.
Impossibile impostare la classe Priority perché non usa un valore valido, come definito nell'enumerazione ProcessPriorityClass .
Esempio
Nell'esempio seguente viene avviata un'istanza del Blocco note. Nell'esempio vengono quindi recuperate e visualizzate varie proprietà del processo associato. L'esempio rileva quando il processo viene chiuso e visualizza il codice di uscita del processo.
using System;
using System.Diagnostics;
namespace ProcessSample
{
class ProcessMonitorSample
{
public static void Main()
{
// Define variables to track the peak
// memory usage of the process.
long peakPagedMem = 0,
peakWorkingSet = 0,
peakVirtualMem = 0;
// Start the process.
using (Process myProcess = Process.Start("NotePad.exe"))
{
// Display the process statistics until
// the user closes the program.
do
{
if (!myProcess.HasExited)
{
// Refresh the current process property values.
myProcess.Refresh();
Console.WriteLine();
// Display current process statistics.
Console.WriteLine($"{myProcess} -");
Console.WriteLine("-------------------------------------");
Console.WriteLine($" Physical memory usage : {myProcess.WorkingSet64}");
Console.WriteLine($" Base priority : {myProcess.BasePriority}");
Console.WriteLine($" Priority class : {myProcess.PriorityClass}");
Console.WriteLine($" User processor time : {myProcess.UserProcessorTime}");
Console.WriteLine($" Privileged processor time : {myProcess.PrivilegedProcessorTime}");
Console.WriteLine($" Total processor time : {myProcess.TotalProcessorTime}");
Console.WriteLine($" Paged system memory size : {myProcess.PagedSystemMemorySize64}");
Console.WriteLine($" Paged memory size : {myProcess.PagedMemorySize64}");
// Update the values for the overall peak memory statistics.
peakPagedMem = myProcess.PeakPagedMemorySize64;
peakVirtualMem = myProcess.PeakVirtualMemorySize64;
peakWorkingSet = myProcess.PeakWorkingSet64;
if (myProcess.Responding)
{
Console.WriteLine("Status = Running");
}
else
{
Console.WriteLine("Status = Not Responding");
}
}
}
while (!myProcess.WaitForExit(1000));
Console.WriteLine();
Console.WriteLine($" Process exit code : {myProcess.ExitCode}");
// Display peak memory statistics for the process.
Console.WriteLine($" Peak physical memory usage : {peakWorkingSet}");
Console.WriteLine($" Peak paged memory usage : {peakPagedMem}");
Console.WriteLine($" Peak virtual memory usage : {peakVirtualMem}");
}
}
}
}
open System.Diagnostics
// Define variables to track the peak
// memory usage of the process.
let mutable peakPagedMem = 0L
let mutable peakWorkingSet = 0L
let mutable peakVirtualMem = 0L
// Start the process.
use myProcess = Process.Start "NotePad.exe"
// Display the process statistics until
// the user closes the program.
while myProcess.WaitForExit 1000 |> not do
if not myProcess.HasExited then
// Refresh the current process property values.
myProcess.Refresh()
printfn ""
// Display current process statistics.
printfn $"{myProcess} -"
printfn "-------------------------------------"
printfn $" Physical memory usage : {myProcess.WorkingSet64}"
printfn $" Base priority : {myProcess.BasePriority}"
printfn $" Priority class : {myProcess.PriorityClass}"
printfn $" User processor time : {myProcess.UserProcessorTime}"
printfn $" Privileged processor time : {myProcess.PrivilegedProcessorTime}"
printfn $" Total processor time : {myProcess.TotalProcessorTime}"
printfn $" Paged system memory size : {myProcess.PagedSystemMemorySize64}"
printfn $" Paged memory size : {myProcess.PagedMemorySize64}"
// Update the values for the overall peak memory statistics.
peakPagedMem <- myProcess.PeakPagedMemorySize64
peakVirtualMem <- myProcess.PeakVirtualMemorySize64
peakWorkingSet <- myProcess.PeakWorkingSet64
if myProcess.Responding then
printfn "Status = Running"
else
printfn "Status = Not Responding"
printfn ""
printfn $" Process exit code : {myProcess.ExitCode}"
// Display peak memory statistics for the process.
printfn $" Peak physical memory usage : {peakWorkingSet}"
printfn $" Peak paged memory usage : {peakPagedMem}"
printfn $" Peak virtual memory usage : {peakVirtualMem}"
Imports System.Diagnostics
Namespace ProcessSample
Class ProcessMonitorSample
Public Shared Sub Main()
' Define variables to track the peak
' memory usage of the process.
Dim peakPagedMem As Long = 0
Dim peakWorkingSet As Long = 0
Dim peakVirtualMem As Long = 0
' Start the process.
Using myProcess = Process.Start("NotePad.exe")
' Display process statistics until
' the user closes the program.
Do
If Not myProcess.HasExited Then
' Refresh the current process property values.
myProcess.Refresh()
Console.WriteLine()
' Display current process statistics.
Console.WriteLine($"{myProcess} -")
Console.WriteLine("-------------------------------------")
Console.WriteLine($" Physical memory usage : {myProcess.WorkingSet64}")
Console.WriteLine($" Base priority : {myProcess.BasePriority}")
Console.WriteLine($" Priority class : {myProcess.PriorityClass}")
Console.WriteLine($" User processor time : {myProcess.UserProcessorTime}")
Console.WriteLine($" Privileged processor time : {myProcess.PrivilegedProcessorTime}")
Console.WriteLine($" Total processor time : {myProcess.TotalProcessorTime}")
Console.WriteLine($" Paged system memory size : {myProcess.PagedSystemMemorySize64}")
Console.WriteLine($" Paged memory size : {myProcess.PagedMemorySize64}")
' Update the values for the overall peak memory statistics.
peakPagedMem = myProcess.PeakPagedMemorySize64
peakVirtualMem = myProcess.PeakVirtualMemorySize64
peakWorkingSet = myProcess.PeakWorkingSet64
If myProcess.Responding Then
Console.WriteLine("Status = Running")
Else
Console.WriteLine("Status = Not Responding")
End If
End If
Loop While Not myProcess.WaitForExit(1000)
Console.WriteLine()
Console.WriteLine($" Process exit code : {myProcess.ExitCode}")
' Display peak memory statistics for the process.
Console.WriteLine($" Peak physical memory usage of the process : {peakWorkingSet}")
Console.WriteLine($" Peak paged memory usage of the process : {peakPagedMem}")
Console.WriteLine($" Peak virtual memory usage of the process : {peakVirtualMem}")
End Using
End Sub
End Class
End Namespace
Commenti
Il valore restituito da questa proprietà rappresenta la priorità aggiornata più di recente del processo. Per ottenere la priorità più aggiornata, è prima necessario chiamare Refresh() il metodo .
Una classe di priorità del processo include un intervallo di livelli di priorità del thread. Thread con priorità diverse in esecuzione nel processo rispetto alla classe di priorità del processo. Win32 usa quattro classi di priorità con sette livelli di priorità di base per classe. Queste classi di priorità del processo vengono acquisite nell'enumerazione ProcessPriorityClass , che consente di impostare la priorità del processo su Idle, NormalHigh, AboveNormal, BelowNormal, o RealTime. In base al tempo trascorso o ad altri boost, il livello di priorità di base può essere modificato dal sistema operativo quando un processo deve essere messo davanti ad altri per l'accesso al processore. Inoltre, è possibile impostare per PriorityBoostEnabled aumentare temporaneamente il livello di priorità dei thread che sono stati tolti dallo stato di attesa. La priorità viene reimpostata quando il processo torna allo stato di attesa.
La BasePriority proprietà consente di visualizzare la priorità iniziale assegnata a un processo. Tuttavia, poiché è di sola lettura, non è possibile utilizzare la BasePriority proprietà per impostare la priorità di un processo. Per modificare la priorità, utilizzare la PriorityClass proprietà , che ottiene o imposta la categoria di priorità complessiva per il processo.
Non è possibile visualizzare la classe di priorità usando Monitoraggio di sistema. Nella tabella seguente viene illustrata la relazione tra i BasePriority valori e PriorityClass .
| BasePriority | PriorityClass |
|---|---|
| 4 | Idle |
| 8 | Normal |
| 13 | High |
| 24 | RealTime |