Environment.ProcessorCount Properti

Definisi

Mendapatkan jumlah prosesor yang tersedia untuk proses saat ini.

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

Nilai Properti

Bilangan bulat bertanda tangan 32-bit yang menentukan jumlah prosesor yang tersedia.

Contoh

Contoh berikut menunjukkan ProcessorCount properti .

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

Keterangan

Pada sistem Linux dan macOS untuk semua versi .NET dan pada sistem Windows yang dimulai dengan .NET 6, API ini mengembalikan minimum:

  • Jumlah prosesor logis pada komputer.
  • Jika proses berjalan dengan afinitas CPU, jumlah prosesor tempat proses diafinisiskan.
  • Jika proses berjalan dengan batas pemanfaatan CPU, batas pemanfaatan CPU dibulatkan ke bilangan bulat berikutnya.

Nilai yang dikembalikan oleh API ini diperbaiki pada .NET startup runtime untuk masa pakai proses. Ini tidak mencerminkan perubahan dalam pengaturan lingkungan saat proses sedang berjalan.

Untuk informasi selengkapnya tentang grup prosesor dan prosesor logis, lihat Grup Prosesor.

Berlaku untuk