PlatformHelper
A helper class to get the number of processors, it updates the numbers of processors every sampling interval.
namespace System.Threading
{
internal static class PlatformHelper
{
private const int PROCESSOR_COUNT_REFRESH_INTERVAL_MS = 30000;
private static volatile int s_processorCount;
private static volatile int s_lastProcessorCountRefreshTicks;
internal static int ProcessorCount {
get {
int tickCount = Environment.TickCount;
int num = s_processorCount;
if (num == 0 || tickCount - s_lastProcessorCountRefreshTicks >= 30000) {
num = (s_processorCount = Environment.ProcessorCount);
s_lastProcessorCountRefreshTicks = tickCount;
}
return num;
}
}
internal static bool IsSingleProcessor => ProcessorCount == 1;
}
}