/// <summary> /// 创建并返回一个Cpu使用率实例,可用于查询操作系统上的CPU时间 /// </summary> /// <returns></returns> public static CpuUsage Create() { if (_cpuUsage == null) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { _cpuUsage = new CpuUsageNt(); } else if (Environment.OSVersion.Platform == PlatformID.Win32Windows) { _cpuUsage = new CpuUsage9x(); } else { throw new NotSupportedException(); } } return(_cpuUsage); }
/// <summary> /// 获取CPU使用率 /// </summary> /// <returns></returns> public static int GetCpuUsage() { return(CpuUsage.Create().Query()); }