次の方法で共有


Process.PriorityClass プロパティ

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

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

プロパティ値

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

例外

例外の種類 条件
Win32Exception プロセス優先順位情報が設定できませんでした。または、関連付けられたプロセスのリソースから取得できませんでした。

または

プロセス ID またはプロセス ハンドルがゼロです。(プロセスはまだ開始していません。)

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

または

プロセス Id を利用できませんでした。

PlatformNotSupportedException Windows 98 を使用しているときに、 PriorityClass を AboveNormal または BelowNormal に設定しました。これらのプラットフォームでは、これらの値の優先順位クラスはサポートされません。

解説

プロセスの優先順位クラスは、一定範囲のスレッドの優先順位に影響します。プロセスで実行される優先順位が異なるスレッドは、そのプロセスの優先順位クラスに対して相対的に実行されます。Win32 は 4 つの優先順位クラスと、クラスごとに 7 つの基本優先順位を使用します。これらのプロセス優先順位クラスは、 ProcessPriorityClass 列挙体にキャプチャされています。これを使用して、プロセス優先順位を IdleNormalHighHighBelowNormal 、または RealTime に設定できます。経過時間またはその他の要因に基づき、プロセスを他のプロセスよりも先にプロセッサにアクセスさせる必要があると判断された場合、オペレーティング システムが基本優先順位を変更することがあります。また、待機状態から抜けたときに一時的にスレッドの優先順位を上げるように、 PriorityBoostEnabled を設定できます。プロセスが待機状態に戻ると、優先順位はリセットされます。

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

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

BasePriority PriorityClass
4 Idle
8 Normal
13 High
24 RealTime

Windows 98 プラットフォームに関する注意点: 優先順位クラスを AboveNormal または BelowNormal に設定すると、例外がスローされます。

使用例

[Visual Basic, C#, C++] メモ帳のインスタンスを起動する例を次に示します。この例では、インスタンスの起動後、関連付けられているプロセスのさまざまなプロパティが取得および表示されます。その後、プロセスの終了を検知し、プロセスの終了コードを表示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

Process クラス | Process メンバ | System.Diagnostics 名前空間 | BasePriority | PriorityBoostEnabled