-1
我在我的應用程序中使用了一個System.Windows.Forms.Timer,它觸發了向四個LiveCharts添加新數據的方法。間隔設置爲1000 ms。它可以像第一個或兩個分鐘一樣正常工作,但間隔變得越來越大,在10分鐘後它只會每隔15秒觸發一次。 我嘗試過使用不同的定時器,沒有任何運氣。可能是因爲應用程序/ LiveCharts的性能太糟糕了,並且由於定時器在UI線程上運行,它必須等待應用程序「準備就緒」?Windows窗體計時器沒有按時執行
謝謝!
定時器設置
graphRefreshTimer = new System.Windows.Forms.Timer();
graphRefreshTimer.Interval = 1000;
graphRefreshTimer.Tick += new EventHandler(refreshUI);
graphRefreshTimer.Start();
refreshUI(基本上只添加新ChartValues到LiveCharts。最多需要100毫秒來運行)
//...
B1VoltageValues.Add(new MeasureModel
{
DateTime = now,
Value = Convert.ToDouble(B1.Voltage)/1000
});
B1CurrentValues.Add(new MeasureModel
{
DateTime = now,
Value = Convert.ToDouble(B1.Current)/1000
});
B1ChargingCapacityValues.Add(new MeasureModel
{
DateTime = now,
Value = Convert.ToDouble(B1.getChargeCapIfTrue())/1000
});
B1DischargingCapacityValues.Add(new MeasureModel
{
DateTime = now,
Value = Convert.ToDouble(B1.getDischargeCapIfTrue())/1000
});
B1EnergyValues.Add(new MeasureModel
{
DateTime = now,
Value = Convert.ToDouble(B1.Energy)/1000
});
//...
請發佈代碼。 –
是的。如果定時器中的代碼花費太長時間,則定時器無法按所需間隔運行。它一次只能運行一個並跳過。 –
我測量了在被觸發的方法中執行代碼需要多長時間,但從未超過100 ms。 – Luigi04