Environment.ProcessorCount Właściwość

Definicja

Pobiera liczbę procesorów dostępnych dla bieżącego procesu.

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

Wartość właściwości

Int32

32-bitowa liczba całkowita ze znakiem określającym liczbę dostępnych procesorów.

Przykłady

W poniższym przykładzie pokazano ProcessorCount właściwość .

// 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.
'

Uwagi

W systemach Linux i macOS dla wszystkich wersji platformy .NET i w systemach Windows począwszy od platformy .NET 6 ten interfejs API zwraca wartość minimalną:

  • Liczba procesorów logicznych na maszynie.
  • Jeśli proces jest uruchomiony z koligacją procesora CPU, liczba procesorów, do których proces jest dołączony.
  • Jeśli proces jest uruchomiony z limitem wykorzystania procesora CPU, limit wykorzystania procesora CPU został zaokrąglony do następnej liczby całkowitej.

Wartość zwracana przez ten interfejs API jest stała podczas uruchamiania środowiska uruchomieniowego platformy .NET dla okresu istnienia procesu. Nie odzwierciedla zmian w ustawieniach środowiska podczas uruchamiania procesu.

Aby uzyskać więcej informacji na temat grup procesorów i procesorów logicznych, zobacz Grupy procesorów.

Dotyczy