这是代码:
public float? cpuView(bool pause , CpuTemperature cpuTemp , Form1 f1 , List<string> myData , float? myCpuTemp , Button b1, decimal numeric)
{
try
{
if (pause == true)
{
}
else
{
Trace.WriteLine("");
foreach (var hardwareItem in myComputer.Hardware)
{
if (hardwareItem.HardwareType == HardwareType.CPU)
{
hardwareItem.Update();
foreach (IHardware subHardware in hardwareItem.SubHardware)
subHardware.Update();
foreach (var sensor in hardwareItem.Sensors)
{
cpuTemp.SetValue("sensor", sensor.Value.ToString());
if (sensor.SensorType == SensorType.Fan)
{
MessageBox.Show("test");
sensor.Hardware.Update();
cpuTemp.GetValue("sensor", sensor.Value.ToString());
if (!f1.IsDisposed)//f1.IsHandleCreated && !f1.IsDisposed)
{
Thread.Sleep(1000);
f1.Invoke(new Action(() => myData.Add("Cpu Temeprature --- " + sensor.Value.ToString())));
}
myCpuTemp = sensor.Value;
//if (sensor.Value > 60)
//{
CpulabelTemp = sensor.Value;
cpuSensorValues.Add(sensor.Value);
if (cpuSensorValues.Count == 300 && sensor.Value >= (float)numeric)
{
float a = ComputeStats(cpuSensorValues).Item1;
float b = ComputeStats(cpuSensorValues).Item2;
float c = ComputeStats(cpuSensorValues).Item3;
Logger.Write("********************************");
Logger.Write("CPU Minimum Temperature Is ===> " + a);
Logger.Write("CPU Maximum Temperature Is ===> " + b);
Logger.Write("CPU Average Temperature Is ===> " + c);
Logger.Write("********************************" + Environment.NewLine);
cpuSensorValues = new List<float?>();
}
b1.Enabled = true;
//}
break;
}
}
}
}
}
}
catch(Exception err)
{
Logger.Write("There was an exception: " + err.ToString());
}
return myCpuTemp;
}
在这一行:
if (sensor.SensorType == SensorType.Fan)
取而代之的是温度。 当它是温度时它没有问题。 但是一旦我将它改为Fan以获得CPU / GPU风扇速度,它就不会跳过这个IF而继续。
它永远不会到达MessageBox.Show行。
可能是什么问题?到目前为止尝试谷歌但没什么。
答案 0 :(得分:1)
您的问题是条件
if (hardwareItem.HardwareType == HardwareType.CPU)
风扇不在CPU上。您需要使用粉丝显示的相应HardwareType,可能是HardwareType.Mainboard
。