private void timer2_Tick(object sender, EventArgs e) { try { timer2.Stop(); UpdateTrafficList(); if (TrafficChart.InvokeRequired) { TrafficChart.Invoke(new EventHandler((sender2, e2) => { UpdateTrafficChart(); }), sender, e); } else { UpdateTrafficChart(); } } catch (Exception ex) { string s = ex.Message; } finally { timer2.Start(); } }
public void UpdateTrafficList(Traffic traffic) { long maxSpeedValue = 0; inboundPoints.Clear(); outboundPoints.Clear(); lock (logList) { if (traffic != null) { this.traffic = traffic; #region Add to trafficLogList TrafficLog previous = logList.Last.Value; TrafficLog current = new TrafficLog( new Traffic(traffic), new Traffic(traffic, previous.total) ); logList.AddLast(current); while (logList.Count > trafficLogSize) { logList.RemoveFirst(); } while (logList.Count < trafficLogSize) { logList.AddFirst(new TrafficLog()); } #endregion } lastLog = logList.Last.Value; foreach (TrafficLog item in logList) { inboundPoints.Add(item.speed.inbound); outboundPoints.Add(item.speed.outbound); maxSpeedValue = Math.Max(maxSpeedValue, Math.Max(item.speed.inbound, item.speed.outbound) ); } } maxSpeed = new FormattedSize(maxSpeedValue); for (int i = 0; i < inboundPoints.Count; i++) { inboundPoints[i] /= maxSpeed.scale; outboundPoints[i] /= maxSpeed.scale; } if (TrafficChart.InvokeRequired) { TrafficChart.Invoke(new Action(UpdateTrafficChart)); } else { UpdateTrafficChart(); } }
private void Controller_TrafficChanged(object sender, EventArgs e) { if (TrafficChart.InvokeRequired) { TrafficChart.Invoke(new EventHandler((sender2, e2) => { UpdateTrafficChart(); }), sender, e); } else { UpdateTrafficChart(); } }