資源簡介
C#讀取電腦CPU溫度winform測試程序,引用OpenHardwareMonitorLib.dll庫,該dll庫在debug夾下,listBox打印溫度數據并顯示

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?OpenHardwareMonitor.Hardware;
namespace?WindowsFormsApplication1
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????public?class?UpdateVisitor?:?IVisitor
????????{
????????????public?void?VisitComputer(IComputer?computer)
????????????{
????????????????computer.Traverse(this);
????????????}
????????????public?void?VisitHardware(IHardware?hardware)
????????????{
????????????????hardware.Update();
????????????????foreach?(IHardware?subHardware?in?hardware.SubHardware)
????????????????????subHardware.Accept(this);
????????????}
????????????public?void?VisitSensor(ISensor?sensor)?{?}
????????????public?void?VisitParameter(IParameter?parameter)?{?}
????????}
????????static?int?getTemperature()
????????{
????????????int?ret?=?0;
????????????Computer?myComputer?=?new?Computer();
????????????UpdateVisitor?updateVisitor?=?new?UpdateVisitor();
????????????myComputer.Open();
????????????myComputer.Accept(updateVisitor);
????????????foreach?(var?hardwareItem?in?myComputer.Hardware)
????????????{
????????????????if?(hardwareItem.HardwareType?==?HardwareType.CPU)
????????????????{
????????????????????foreach?(var?sensor?in?hardwareItem.Sensors)
????????????????????{
????????????????????????if?(sensor.SensorType?==?SensorType.Temperature)
????????????????????????{
????????????????????????????ret?=?Convert.ToInt32(sensor.Value);
????????????????????????}
????????????????????}
????????????????}
????????????}
????????????return?ret;
????????}
????????private?void?timer1_Tick(object?sender?EventArgs?e)
????????{
????????????int?t?=?getTemperature();
????????????label1.Text?=?“Now?CPU?Temp=“+t.ToString();
????????????listBox1.Items.Add(“CPU?Temp=“?+?t.ToString());
????????}?
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????274944??2012-05-27?02:36??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\OpenHardwareMonitorLib.dll
?????文件??????10240??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
?????文件??????28160??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
?????文件??????22472??2018-09-03?11:32??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
?????文件????????490??2018-04-12?07:35??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
?????文件?????274944??2012-05-27?02:36??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\OpenHardwareMonitorLib.dll
?????文件???????9728??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.exe
?????文件??????26112??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.pdb
?????文件??????22472??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe
?????文件????????490??2018-04-12?07:35??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.vshost.exe.manifest
?????文件???????2040??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
?????文件???????2930??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
?????文件???????6011??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
?????文件???????1451??2018-09-03?11:16??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7250??2018-09-03?11:06??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件?????274944??2012-05-27?02:36??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\OpenHardwareMonitorLib.dll
?????文件???????1644??2018-09-03?11:32??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件????????975??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
?????文件???????7121??2018-09-03?11:17??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csprojResolveAssemblyReference.cache
?????文件??????10240??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe
?????文件????????180??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources
?????文件??????28160??2018-09-03?11:31??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb
?????文件????????180??2018-09-03?11:17??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources
?????文件???????7254??2018-09-03?11:21??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache
?????文件?????274944??2012-05-27?02:36??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\OpenHardwareMonitorLib.dll
?????文件???????1455??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件????????975??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.csproj.GenerateResource.Cache
?????文件???????9728??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.exe
?????文件????????180??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.Form1.resources
?????文件??????26112??2018-09-03?11:34??我的讀取CPU溫度測試1\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.pdb
............此處省略26個文件信息
- 上一篇:winform 自定義日期控件
- 下一篇:小程序獲取openid(親測通過)
評論
共有 條評論