v2019.08.19

This commit is contained in:
pypy
2019-08-19 23:21:08 +09:00
parent d725c8f1e3
commit 26b371fd0f
19 changed files with 768 additions and 515 deletions

View File

@@ -13,36 +13,32 @@ namespace VRCX
public static float CpuUsage { get; private set; }
private static Thread m_Thread;
public static void Start()
public static void Init()
{
if (m_Thread == null)
m_Thread = new Thread(() =>
{
m_Thread = new Thread(() =>
PerformanceCounter counter = null;
try
{
PerformanceCounter cpuCounter = null;
try
{
cpuCounter = new PerformanceCounter("Processor Information", "% Processor Utility", "_Total", true);
}
catch
{
}
try
{
if (cpuCounter == null)
{
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
}
}
catch
counter = new PerformanceCounter("Processor Information", "% Processor Utility", "_Total", true);
}
catch
{
}
try
{
if (counter == null)
{
counter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
}
}
catch
{
}
if (counter != null)
{
while (m_Thread != null)
{
if (cpuCounter != null)
{
CpuUsage = cpuCounter.NextValue();
}
try
{
Thread.Sleep(1000);
@@ -51,31 +47,23 @@ namespace VRCX
{
// ThreadInterruptedException
}
CpuUsage = counter.NextValue();
}
if (cpuCounter != null)
{
cpuCounter.Dispose();
}
});
m_Thread.Start();
}
counter.Dispose();
}
})
{
IsBackground = true
};
m_Thread.Start();
}
public static void Stop()
public static void Exit()
{
var thread = m_Thread;
if (thread != null)
{
m_Thread = null;
try
{
thread.Interrupt();
thread.Join();
}
catch
{
}
}
var T = m_Thread;
m_Thread = null;
T.Interrupt();
T.Join();
}
}
}