System命名空间中的Environment.ProcessorCount属性可以解决这个问题:
public static int ProcessorCount { get; }
此属性给出了CPU逻辑核心数,而不是物理核心数。如在Intel超线程环境下,逻辑核心数与物理核心数不同