我已經找到了如何獲得OHM在C#無法獲得OpenHardwareMonitorLib.dll工作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenHardwareMonitor.Hardware;
namespace OpenHardwareMonitorReport
{
class Program
{
static void Main(string[] args)
{
Computer computer = new Computer();
computer.Open();
var temps = new List<decimal>();
foreach (var hardware in computer.Hardware)
{
if (hardware.HardwareType != HardwareType.CPU)
continue;
hardware.Update();
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType != SensorType.Temperature)
{
if (sensor.Value != null)
temps.Add((decimal)sensor.Value);
}
}
}
foreach (decimal temp in temps)
{
Console.WriteLine(temp);
}
Console.ReadLine();
}
}
}
這應該顯示一些傳感器數據,但是當我運行它給我這個錯誤做工非常舉幾個例子:
託管調試助手'PInvokeStackImbalance'在'C:\ Users \ Josh \ Desktop \ DLLTutorial \ HardwareMonitor \ HardwareMonitor \ bin \ Debug \ HardwareMonitor.vshost.exe'中檢測到問題。 附加信息:對PInvoke函數'PInvokeDelegateFactoryInternalAssembly!PInvokeDelegateFactoryInternalWrapperType13 :: ADL_Main_Control_Create'的調用使堆棧不平衡。這很可能是因爲託管的PInvoke簽名與非託管目標籤名不匹配。檢查PInvoke簽名的調用約定和參數是否與目標非託管簽名相匹配。
我已經從OHM svn下載了.dll文件,把它放到了我的項目中,並添加了對它的引用,並且它在「computer.Open()」行中崩潰了。與我上面發佈的錯誤。
請幫忙!
我剛剛下載了最新的示例並運行了您提供的代碼。它在我的機器上運行良好。你運行的是什麼版本的Windows/.Net? – scottm 2012-07-20 17:56:44
Windows 7 Professional 64位,.Net 4.0 – 2012-07-20 18:00:12
這就是我正在運行的。你安裝了SP1嗎? – scottm 2012-07-20 18:01:15