我正在尝试使用CPU来获取我的OpenHardwareMonitorLib核心的温度,但是这不能为我返回温度。
我环顾四周,发现这几乎是一个到处都有的问题,但我不能让它工作。
如果有人能告诉我这方面哪里出了问题,我将不胜感激。
这是我的代码:
using System;
using System.Linq;
using System.Management;
using OpenHardwareMonitor.Collections;
using OpenHardwareMonitor.Hardware;
using OxyPlot;
using OxyPlot.Series;
namespace cs_TempReader
{
class Program
{
private DateTime now;
protected readonly ListSet<ISensor> active = new ListSet<ISensor>();
public event SensorEventHandler SensorAdded;
public event SensorEventHandler SensorRemoved;
protected virtual void ActivateSensor(ISensor sensor)
{
if (active.Add(sensor))
if (SensorAdded != null)
SensorAdded(sensor);
}
private static void Main(string[] args)
{
var myComputer = new Computer();
myComputer.CPUEnabled = true;
myComputer.ToCode();
myComputer.Open();
foreach (var hardwareItem in myComputer.Hardware)
{
hardwareItem.Update();
hardwareItem.GetReport();
Console.WriteLine(hardwareItem.GetReport());
var series = new LineSeries();
foreach (var sensor in hardwareItem.Sensors)
{
if (sensor.SensorType == SensorType.Temperature)
{
Console.WriteLine("{0} {1} {2} = {3}", sensor.Name, sensor.Hardware, sensor.SensorType, sensor.Value);
}
}
}
}
}
}我的最终目标是能够将其绑定到一个更大的应用程序中。
发布于 2016-06-18 08:11:35
您需要在应用程序中请求更高的执行级别,这样代码才能正常工作。
要做到这一点,你必须:
在此之后,您必须更改清单上的以下行:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />要这样做:
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />发布于 2018-02-01 14:21:28
也许你必须强制你的应用程序以管理员身份运行,然后你的代码才能工作。
右击Project > Add New Item,选择"Application Manifest File“。
更改
<requestedExecutionLevel>元素添加到:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />这是教程,你可以看看。
http://www.lattepanda.com/topic-f11t3004.html
https://stackoverflow.com/questions/27296543
复制相似问题