Environment.ProcessorCount プロパティ

定義

現在のプロセスで使用できるプロセッサの数を取得します。

public:
 static property int ProcessorCount { int get(); };
public static int ProcessorCount { get; }
member this.ProcessorCount : int
Public Shared ReadOnly Property ProcessorCount As Integer

プロパティ値

Int32

使用可能なプロセッサの数を指定する 32 ビット符号付き整数。

ProcessorCountプロパティの例を次に示します。

// This example demonstrates the 
//     Environment.ProcessorCount property.
using namespace System;
int main()
{
   Console::WriteLine( "The number of processors on this computer is {0}.", Environment::ProcessorCount );
}

/*
This example produces the following results:

The number of processors on this computer is 1.
*/
// This example demonstrates the
//     Environment.ProcessorCount property.
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine("The number of processors " +
        "on this computer is {0}.",
        Environment.ProcessorCount);
    }
}
/*
This example produces the following results:

The number of processors on this computer is 1.
*/
// This example demonstrates the
//     Environment.ProcessorCount property.
open System

printfn $"The number of processors on this computer is {Environment.ProcessorCount}."

// This example produces the following results:
//     The number of processors on this computer is 1.
' This example demonstrates the 
'     Environment.ProcessorCount property.
Class Sample
   Public Shared Sub Main()
      Console.WriteLine("The number of processors " & _
                        "on this computer is {0}.", _
                        Environment.ProcessorCount)
   End Sub
End Class
'
'This example produces the following results:
'
'The number of processors on this computer is 1.
'

注釈

すべての .NET バージョンの Linux システムとmacOS システム、および .NET 6 以降のWindows システムでは、この API は次の最小値を返します。

  • マシン上の論理プロセッサの数。
  • プロセスが CPU アフィニティありで実行されている場合、プロセスとのアフィニティがあるプロセッサの数。
  • プロセスが CPU 使用率の上限付きで実行されている場合、CPU 使用率の上限は次の整数に切り上げられます。

この API によって返される値は、プロセスの有効期間中、.NET ランタイムの起動時に固定されます。 プロセスの実行中の環境設定の変更は反映されません。

プロセッサ グループと論理プロセッサの詳細については、「 プロセッサ グループ」を参照してください。

適用対象