PerformanceCounter CPUCounter = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
chart1.Series["Usage %"].Points.AddY(CPUCounter);
返回错误消息:
System.ArgumentException:'系列数据点不支持值 键入System.Diagnostics.PerformanceCounter仅这些类型的值 可以使用:Double,Decimal,Single,int,long,uint,ulong,String, DateTime,简称,ushort。'
我正在尝试在线图上显示CPU使用率数据以显示使用历史记录。
答案 0 :(得分:2)
PerformanceCounter类仅用于引用特定的NT性能计数器组件。有了实例后,您可以拨打NextSample()
给CounterSample
,或者只使用RawValue
属性,如果尚未调用,则调用NextSample。
我希望这对你有用,给予或采取舍入/缩放:
chart1.Series["Usage %"].Points.AddY(CPUCounter.RawValue); // Use RawValue property here
RawValue返回一个long,你得到的异常消息表明长值是可以接受的。