Environment.ProcessorCount Eigenschaft

Definition

Ruft die Anzahl der Prozessoren ab, die für den aktuellen Prozess verfügbar sind.

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

Eigenschaftswert

Die 32-Bit-Ganzzahl, die die Anzahl der verfügbaren Prozessoren angibt.

Beispiele

Im folgenden Beispiel wird die ProcessorCount Eigenschaft veranschaulicht.

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

Hinweise

Auf Linux- und macOS-Systemen für alle .NET-Versionen und auf Windows Systemen ab .NET 6 gibt diese API folgendes Minimum zurück:

  • Die Anzahl der logischen Prozessoren auf dem Computer.
  • Wenn der Prozess mit CPU-Affinität ausgeführt wird, ist die Anzahl der Prozessoren, zu denen der Prozess affinitiert ist.
  • Wenn der Prozess mit einem CPU-Auslastungslimit ausgeführt wird, wird die CPU-Auslastungsgrenze auf die nächste ganze Zahl aufgerundet.

Der von dieser API zurückgegebene Wert wird für die Prozesslebensdauer bei .NET Laufzeitstart behoben. Es spiegelt keine Änderungen an den Umgebungseinstellungen wider, während der Prozess ausgeführt wird.

Weitere Informationen zu Prozessorgruppen und logischen Prozessoren finden Sie unter Prozessorgruppen.

Gilt für: