Environment.ProcessorCount Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the number of processors available to the current process.
public:
static property int ProcessorCount { int get(); };
public static int ProcessorCount { get; }
static member ProcessorCount : int
Public Shared ReadOnly Property ProcessorCount As Integer
Property Value
The 32-bit signed integer that specifies the number of processors that are available.
Examples
The following example demonstrates the ProcessorCount property.
// 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.
'
Remarks
On Linux and macOS systems for all .NET versions and on Windows systems starting with .NET 6, this API returns the minimum of:
- The number of logical processors on the machine.
- If the process is running with CPU affinity, the number of processors that the process is affinitized to.
- If the process is running with a CPU utilization limit, the CPU utilization limit rounded up to the next whole number.
The value returned by this API is fixed at .NET runtime startup for the process lifetime. It does not reflect changes in the environment settings while the process is running.
For more information about processor groups and logical processors, see Processor Groups.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기