This is the code:
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;
}
In this line:
if (sensor.SensorType == SensorType.Fan)
Instead Fan it was Temperature. When it was Temperature it was working no problems. But once i changed it to Fan to get the CPU/GPU Fan speed it dosen't get in it's jumping over this IF and keep on.
It's never get to the MessageBox.Show line.
What could be the problem ? Tried to google but nothing so far.
Your problem is the conditional
The fans are not on the CPU. You need to use the appropriate HardwareType that the fans show up on, probably
HardwareType.Mainboard.