C# api

回眸婉约 2011-06-01 10:52:30
RT:
麻烦解释下 我看好多程序都要用这个 好像获取什么CPU 温度什么的··都是用这个
然后 求详解教程
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-06-01
  • 打赏
  • 举报
回复
Double CPUtprt = 0;

System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(@"root\WMI", "Select * From MSAcpi_ThermalZoneTemperature");

foreach (System.Management.ManagementObject mo in mos.Get())

{

CPUtprt = Convert.ToDouble(Convert.ToDouble(mo.GetPropertyValue("CurrentTemperature").ToString()) - 2732) / 10;

textBox1.Text = ("CPU 溫度 : " + CPUtprt.ToString() + " °C");

}
ycproc 2011-06-01
  • 打赏
  • 举报
回复


using System;
using System.Collections.Generic;
using System.Text;

/// <summary>
/// Defines an abstract base class for implementations of CPU usage counters.
/// </summary>
public abstract class CpuUsage
{
/// <summary>
/// Creates and returns a CpuUsage instance that can be used to query the CPU time on this operating system.
/// </summary>
/// <returns>An instance of the CpuUsage class.</returns>
/// <exception cref="NotSupportedException">This platform is not supported -or- initialization of the CPUUsage object failed.</exception>
public static CpuUsage Create()
{
if (m_CpuUsage == null)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
m_CpuUsage = new CpuUsageNt();
//else if (Environment.OSVersion.Platform == PlatformID.Win32Windows)
// m_CpuUsage = new CpuUsage9x();
else
throw new NotSupportedException();
}
return m_CpuUsage;
}
/// <summary>
/// Determines the current average CPU load.
/// </summary>
/// <returns>An integer that holds the CPU load percentage.</returns>
/// <exception cref="NotSupportedException">One of the system calls fails. The CPU time can not be obtained.</exception>
public abstract int Query();
/// <summary>
/// Holds an instance of the CPUUsage class.
/// </summary>
private static CpuUsage m_CpuUsage = null;
}


x8bits 2011-06-01
  • 打赏
  • 举报
回复
API = Application Programming Interface
threenewbee 2011-06-01
  • 打赏
  • 举报
回复
取系统信息用 WMI 就可以了。

API就是一些标准的操作系统调用而已。参考资料是 Windows Platform SDK。在微软网站可以下载。

不过SDK文档是英文的,并且是面向C语言的。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧