Environment.ProcessorCount Özellik

Tanım

Geçerli işlem için kullanılabilen işlemci sayısını alır.

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

Özellik Değeri

Kullanılabilir işlemci sayısını belirten 32 bit imzalı tamsayı.

Örnekler

Aşağıdaki örnekte özelliği gösterilmektedir ProcessorCount .

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

Açıklamalar

Tüm .NET sürümleri için Linux ve macOS sistemlerinde ve .NET 6'dan itibaren Windows sistemlerde bu API en az şunları döndürür:

  • Makinedeki mantıksal işlemci sayısı.
  • İşlem CPU benzenşimi ile çalışıyorsa, işlemin benzenlendiği işlemci sayısı.
  • İşlem bir CPU kullanım sınırıyla çalışıyorsa, CPU kullanım sınırı bir sonraki tamsayıya yuvarlandı.

Bu API tarafından döndürülen değer, işlem ömrü boyunca .NET çalışma zamanı başlangıcında düzeltilir. İşlem çalışırken ortam ayarlarındaki değişiklikleri yansıtmaz.

İşlemci grupları ve mantıksal işlemciler hakkında daha fazla bilgi için bkz. İşlemci Grupları.

Şunlara uygulanır