private void addReading(MeasurementObject m) { lock (pastReadings) { if (pastReadings.Count % ((int)this.Width / 2) == 0) { List <MeasurementObject> oldData = new List <MeasurementObject> { }; oldData.AddRange(pastReadings); pastReadings.Clear(); for (int i = 0; i < oldData.Count; i += 2) { var a = oldData[i]; var b = oldData[i]; if (i != oldData.Count) { b = oldData[i + 1]; } MeasurementObject mn = new MeasurementObject(b.CaptureTime, a.startTime, (a.Voltage + b.Voltage) / 2, (a.Current + b.Current) / 2, b.mAh, b.mWh); pastReadings.Add(mn); } } pastReadings.Add(m); } }
private void addreading(string[] data) {//process the incoming data double voltage, current, mah, mwh; voltage = current = mah = mwh = 0; current = double.Parse(data[1]); voltage = double.Parse(data[2]) / 1000; mah = double.Parse(data[3]) / 1000; mwh = double.Parse(data[4]) / 1000; MeasurementObject m = new MeasurementObject(DateTime.Now, startTime, voltage, current, mah, mwh); //add the entry to the list latestRecording = m; if (m.Current != 0 && fileStarted && !filePaused) { lock (pastReadings) { try { Application.Current.Dispatcher.BeginInvoke(new Action(() => addReading(m))); } catch { } // pastReadings.Add(m); m.Append(currentFile, startTime); } //write it out to the save file } updateDisplay(); }