To get the system CPU count in C#, you can use the Environment.ProcessorCount
property. This property returns the number of processors on the current machine.
Here's an example code snippet:
main.cs187 chars11 lines
The Environment.ProcessorCount
property returns an integer representing the number of processors on the current machine. This value can be useful for certain types of multithreaded programming, as you can tailor the number of threads you use to the number of available processors.
Note that the Environment.ProcessorCount
property returns the number of logical processors on the machine, which includes hyper-threaded cores. In many cases, this will be twice the number of physical cores.
gistlibby LogSnag