Process.PriorityClass プロパティ

定義

関連付けられたプロセスの全体的な優先順位カテゴリを取得または設定します。

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

プロパティ値

ProcessPriorityClass

プロセスの BasePriority を計算するときに使用する、関連付けられたプロセスの優先順位カテゴリ。

例外

関連付けられているプロセスのリソースからプロセス優先度情報を設定できないか、取得できませんでした。

または

プロセス識別子またはプロセス ハンドルが 0 です。 (プロセスは開始されていません。)

リモート コンピューターで実行されているプロセスの PriorityClass プロパティにアクセスしようとしています。 このプロパティはローカル コンピューターで実行中のプロセスに対してのみ使用可能です。

プロセス Id が使用できません。

ProcessPriorityClass 列挙体で定義されている有効な値が使用されていないため、優先度クラスを設定できません。

次の例では、メモ帳のインスタンスを開始します。 次に、この例では、関連付けられているプロセスのさまざまなプロパティを取得して表示します。 この例では、プロセスがいつ終了するかを検出し、プロセスの終了コードを表示します。

#using <system.dll>

using namespace System;
using namespace System::Diagnostics;
int main()
{
   
   // Define variables to track the peak
   // memory usage of the process.
   _int64 peakPagedMem = 0,peakWorkingSet = 0,peakVirtualMem = 0;
   Process^ myProcess = nullptr;
   try
   {
      
      // Start the 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( "{0} -", myProcess );
            Console::WriteLine( "-------------------------------------" );
            Console::WriteLine( "  physical memory usage: {0}", myProcess->WorkingSet64 );
            Console::WriteLine( "  base priority: {0}", myProcess->BasePriority );
            Console::WriteLine( "  priority class: {0}", myProcess->PriorityClass );
            Console::WriteLine( "  user processor time: {0}", myProcess->UserProcessorTime );
            Console::WriteLine( "  privileged processor time: {0}", myProcess->PrivilegedProcessorTime );
            Console::WriteLine( "  total processor time: {0}", myProcess->TotalProcessorTime );
            Console::WriteLine("  PagedSystemMemorySize64: {0}", myProcess->PagedSystemMemorySize64);
            Console::WriteLine("  PagedMemorySize64: {0}", 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: {0}", myProcess->ExitCode );
      
      // Display peak memory statistics for the process.
      Console::WriteLine( "Peak physical memory usage of the process: {0}", peakWorkingSet );
      Console::WriteLine( "Peak paged memory usage of the process: {0}", peakPagedMem );
      Console::WriteLine( "Peak virtual memory usage of the process: {0}", peakVirtualMem );
   }
   finally
   {
      if ( myProcess != nullptr )
      {
         myProcess->Close();
      }
   }

}
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}");
            }
        }
    }
}
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

注釈

このプロパティによって返される値は、プロセスの最後に更新された優先度を表します。 最新の優先順位を取得するには、まずメソッドを呼び出す Refresh() 必要があります。

プロセス優先度クラスには、スレッド優先度レベルの範囲が含まれます。 プロセスで実行されている優先順位が異なるスレッドは、プロセスの優先順位クラスを基準にして実行されます。 Win32 では、クラスごとに 7 つの基本優先度レベルを持つ 4 つの優先度クラスが使用されます。 これらのプロセス優先度クラスは列挙に ProcessPriorityClass キャプチャされます。これにより、プロセスの優先順位を Idle、、 NormalHighAboveNormalBelowNormal、または RealTimeに設定できます。 経過時間やその他のブーストに基づいて、プロセッサにアクセスするためにプロセスを他のプロセスよりも優先する必要があるときに、オペレーティング システムによって基本優先度レベルを変更できます。 さらに、待機状態から取り出されたスレッドの優先度レベルを一時的に昇格するように設定 PriorityBoostEnabled できます。 プロセスが待機状態に戻ると、優先度がリセットされます。

この BasePriority プロパティを使用すると、プロセスに割り当てられている開始優先度を表示できます。 ただし、このプロパティは読み取り専用であるため、このプロパティを BasePriority 使用してプロセスの優先順位を設定することはできません。 優先度を変更するには、プロセスの PriorityClass 全体的な優先度カテゴリを取得または設定するプロパティを使用します。

優先度クラスは、システム モニターを使用して表示できません。 次の表に、値とPriorityClass値の関係をBasePriority示します。

BasePriority PriorityClass
4 Idle
8 Normal
13 High
24 RealTime

適用対象

こちらもご覧ください