• 大小: 538KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-17
  • 语言: C#
  • 标签: VS2012  C#  CPU  CPU温度  

资源简介

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个文件信息

评论

共有 条评论