using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Uchukamen.WZero3
{
class CPUStatus
{
[DllImport("COREDLL.DLL")]
private extern static uint GetTickCount();
{
class CPUStatus
{
[DllImport("COREDLL.DLL")]
private extern static uint GetTickCount();
[DllImport("COREDLL.DLL")]
private extern static uint GetIdleTime();
private extern static uint GetIdleTime();
private static uint dwStartTick = 0;
private static uint dwIdleSt = 0;
private static uint dwIdleSt = 0;
/// <summary>
/// CPU使用率
/// </summary>
/// <returns>uint 0:最小-100:最大</returns>
public uint GetCPU()
{
uint dwStopTick = GetTickCount();
uint dwIdleEd = GetIdleTime();
uint idle = ((100 * (dwIdleEd – dwIdleSt)) / (dwStopTick – dwStartTick));
/// CPU使用率
/// </summary>
/// <returns>uint 0:最小-100:最大</returns>
public uint GetCPU()
{
uint dwStopTick = GetTickCount();
uint dwIdleEd = GetIdleTime();
uint idle = ((100 * (dwIdleEd – dwIdleSt)) / (dwStopTick – dwStartTick));
dwStartTick = dwStopTick;
dwIdleSt = dwIdleEd;
uint cpu = 100 – idle;
Debug.WriteLine(cpu.ToString());
return cpu;
}
}
}
dwIdleSt = dwIdleEd;
uint cpu = 100 – idle;
Debug.WriteLine(cpu.ToString());
return cpu;
}
}
}
呼び出し
CPUStatus cpuStat = new CPUStatus();
uint cpu = cpuStat.GetCPU();