有两个线程,一个去读数据,另外一个把读取的数据显示出来,可是没当我点暂停然后开始的时候,程序就变得很卡,而且做出的曲线也不流畅了。哪位大神帮我看看代码,谢谢了!
创建线程
timer1.Interval = TimeSpan.FromMilliseconds(33);
timer1.Tick += new EventHandler(timer_tick1);
timer1.Start();
thread1 = new Thread(new ThreadStart(Data));
thread1.IsBackground = true;
thread1.Start();
停止按钮
if (thread1.IsAlive)
{
thread1.Abort();
}
timer1.Stop();
if (_Data == null)
{
return;
}
else
{
while (_Data.Count > 0)
{
Point item;
_Data.TryTake(out item);
}
}
创建一个队列
private readonly BlockingCollection<Point> _Data = new BlockingCollection<Point>(new ConcurrentQueue<Point>());
读取数据
for (int i = 0; i < Data1.Count(); i += 1)
{
_Data.Add(new Point(Time1[i], Data1[i]));
}
把读取的数据写入曲线
for (int i = 0; i < count; ++i)
{
Point sample = _Data.Take();
times[i] = sample.X;
values[i] = sample.Y;
}
ds0.Append(times, values);
第一个点击开始的时候,程序运行的很好,之后暂停在开始,程序开始卡了,而且曲线也不连续了。