NadekoBot/NadekoBot.Core/Common/PlatformHelper.cs

25 lines
746 B
C#
Raw Normal View History

using System;
2017-07-17 19:42:36 +00:00
namespace NadekoBot.Common
{
2016-11-14 11:19:58 +00:00
public static class PlatformHelper
{
private const int ProcessorCountRefreshIntervalMs = 30000;
private static volatile int _processorCount;
private static volatile int _lastProcessorCountRefreshTicks;
2016-11-14 11:19:58 +00:00
public static int ProcessorCount {
get {
var now = Environment.TickCount;
if (_processorCount == 0 || (now - _lastProcessorCountRefreshTicks) >= ProcessorCountRefreshIntervalMs)
{
_processorCount = Environment.ProcessorCount;
_lastProcessorCountRefreshTicks = now;
}
return _processorCount;
}
}
}
}