Environment.ProcessorCount Vlastnost

Definice

Získá počet procesorů dostupných pro aktuální proces.

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

Hodnota vlastnosti

Int32

32bitové celé číslo podepsaného, které určuje počet dostupných procesorů.

Příklady

Následující příklad ukazuje ProcessorCount vlastnost.

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

Poznámky

V systémech Linux a macOS pro všechny verze .NET a v systémech Windows začínajících na .NET 6 vrátí toto rozhraní API minimum:

  • Počet logických procesorů na počítači.
  • Pokud proces běží se spřažením procesoru, počet procesorů, ke kterým je proces spřažení.
  • Pokud proces běží s limitem využití procesoru, zaokrouhluje se limit využití procesoru nahoru na další celé číslo.

Hodnota vrácená tímto rozhraním API je opravena při spuštění modulu runtime .NET po dobu životnosti procesu. Při spuštění procesu neodráží změny v nastavení prostředí.

Další informace o skupinách procesorů a logických procesorech najdete v tématu Skupiny procesorů.

Platí pro