我想从A / C的16个通道中获取预览,我需要25-40Hz的刷新率(每25-40ms更新一次)。我很少使用线程和计时器的组合,但仅在最多4个图表上就获得了令人满意的性能。在扩展图表范围以刷新后,添加的图表的帧速率约为0.5 / s。我应用了快速折线图。
我应用了一个计时器,每20毫秒从A / C获取新数据。经过一些测试,看起来添加一个单独的线程来处理每个图表(在给定时间内休眠,然后更新绘图)效率不高(至少按照我的方式)。
所以问题是:如何有效地处理多个图表。
下面,我介绍了代码的最重要部分。
System.Timers.Timer tim = new System.Timers.Timer(20);
System.Threading.Thread[] t;
int HighChan = 15;
//button which runs the preview, executed once
private void previewB_Click(object sender, EventArgs e)
{
t = new System.Threading.Thread[HighChan + 1];
for (int i = 0; i <HighChan+1; i++)
{
charts[i].Series.SuspendUpdates();
//run a separate thread for each chart
t[i] = new System.Threading.Thread(new ParameterizedThreadStart(updatePlot));
t[i].Start(i);
}
//run timer to get new data with tim.interval
tim.Stop();
tim.Elapsed += new ElapsedEventHandler(this.OnTimedEvent);
tim.Start();
} …Run Code Online (Sandbox Code Playgroud)