Ejemplo n.º 1
0
        private void timer_Tick(object sender, EventArgs e)
        {
            if (!IsDeviceSelected)
            {
                timestampForDbUpdate = DateTime.MinValue;
                return;
            }
            var readings = dbUpdater.GetNewReadings(SelectedDeviceLocation, timestampForDbUpdate);

            if (readings == null || readings.Count == 0)
            {
                return;
            }

            sensorReadings.Invoke((MethodInvoker) delegate
            {
                var points = sensorReadings.Series["Readings"].Points;
                while (points.Count > 500)
                {
                    points.RemoveAt(0);
                }

                foreach (var reading in readings)
                {
                    points.AddY(reading);
                }
            });

            timestampForDbUpdate = DateTime.Now;
            timestampForDbUpdate.AddMilliseconds(-250);
        }