2016-10-10 04:12:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Common
|
2016-10-10 04:12:22 +00:00
|
|
|
|
{
|
2016-11-14 11:19:58 +00:00
|
|
|
|
public static class PlatformHelper
|
2016-10-10 04:12:22 +00:00
|
|
|
|
{
|
|
|
|
|
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 {
|
2016-10-10 04:12:22 +00:00
|
|
|
|
get {
|
|
|
|
|
var now = Environment.TickCount;
|
|
|
|
|
if (_processorCount == 0 || (now - _lastProcessorCountRefreshTicks) >= ProcessorCountRefreshIntervalMs)
|
|
|
|
|
{
|
|
|
|
|
_processorCount = Environment.ProcessorCount;
|
|
|
|
|
_lastProcessorCountRefreshTicks = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _processorCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|