public void UpdateBoxes() { var chart = new Chart(ref cartesianChart1); ThreadStart startDrawing = new ThreadStart(delegate() { while (drawingThread.ThreadState == ThreadState.Running) { currentTextBox.Invoke(new Action(delegate() { currentTextBox.Text = DataAggregator.CurrentValue() + " °C"; })); avgTextBox.Invoke(new Action(delegate() { avgTextBox.Text = DataAggregator.AvgValue() + " °C"; })); minTextBox.Invoke(new Action(delegate() { minTextBox.Text = DataAggregator.MinValue() + " °C"; })); maxTextBox.Invoke(new Action(delegate() { maxTextBox.Text = DataAggregator.MaxValue() + " °C"; })); cartesianChart1.Invoke(new Action(delegate() { chart.DrawChart(ref dispChartBtn, DataAggregator.dataList.Select(x => x.Value)); })); Thread.Sleep(10000); } }); drawingThread = new Thread(startDrawing); drawingThread.Start(); }
public void ListenPort(SerialPort serialPort) { OpenSerialPort(serialPort); if (serialPort.IsOpen) { ts = new ThreadStart(delegate() { while (listeningThread.ThreadState == ThreadState.Running) { var val = serialPort.ReadLine(); DataAggregator.AggregateData(val); Thread.Sleep(10000); } }); listeningThread = new Thread(ts); if (listeningThread.ThreadState == ThreadState.Suspended) { listeningThread.Resume(); } else { listeningThread.Start(); } } }