Environment.ProcessorCount Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri az aktuális folyamat számára elérhető processzorok számát.
public:
static property int ProcessorCount { int get(); };
public static int ProcessorCount { get; }
static member ProcessorCount : int
Public Shared ReadOnly Property ProcessorCount As Integer
Tulajdonság értéke
Az elérhető processzorok számát meghatározó 32 bites aláírt egész szám.
Példák
Az alábbi példa a tulajdonságot ProcessorCount mutatja be.
// 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.
'
Megjegyzések
Linux és macOS rendszereken az összes .NET verzióhoz és Windows rendszereken a .NET 6-os verziótól kezdve ez az API a következőket adja vissza:
- A gépen található logikai processzorok száma.
- Ha a folyamat cpu-affinitással fut, a folyamat által affinitt processzorok száma.
- Ha a folyamat cpu-kihasználtsági korláttal fut, a processzor kihasználtsági korlátja felfelé kerekítve lesz a következő egész számra.
Az API által visszaadott érték .NET futásidejű indításkor lesz rögzítve a folyamat teljes élettartama alatt. Nem tükrözi a környezeti beállítások változásait a folyamat futtatása közben.
További információ a processzorcsoportokról és a logikai processzorokról: Processzorcsoportok.