private void Timer1sSetEnable(bool ON) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (InvokeRequired) { SetTimerCallback d = new SetTimerCallback(Timer1sSetEnable); this.Invoke(d, new object[] { ON }); } else { this.timer1s.Enabled = ON; } }
private void OnTimedEvent(Object source, ElapsedEventArgs e) { try { if (chartControl.InvokeRequired) { SetTimerCallback callback = new SetTimerCallback(OnTimedEvent); //todo safer invoke look up bism try { Invoke(callback, new object[] { source, e }); } catch { } } else { //Todo delete this once http stability fix is done if ((DateTime.Now - _connectionTime).TotalMinutes > 8) { _server.Disconnect(); _server.Connect(_serverConnectionString); _connectionTime = DateTime.Now; } _seriesData[0] = GetNewXAxisMarkerPointsFromAs(); //rebind chartControl.Series.Clear(); //for each X axis marker for (int i = _seriesData.Length - 1; i > 0; i--) { //push back one category _seriesData[i] = _seriesData[i - 1]; //foreach series for the X axis marker we are populating: ... foreach (KeyValuePair <string, SeriesPoint> entry in _seriesData[i]) { //add the series if not there yet if (chartControl.Series.FindByName(entry.Key) == null) { Series series = new Series(entry.Key); series.ChartType = SeriesChartType.StackedColumn; chartControl.Series.Add(series); } //add the data point for the series DataPoint point = new DataPoint(); point.SetValueXY(entry.Value.XAxisLabel, entry.Value.MemoryUsedMegabytes); point.ToolTip = string.Format($"{entry.Value.XAxisLabel} - {entry.Key}: {string.Format("{0:#,###0}", entry.Value.MemoryUsedMegabytes)} MB"); chartControl.Series[entry.Key].Points.Add(point); } } PaintChart(); } } catch (Exception exc) { //Workaround for timeout over HTTP. Try to reconnect - todo delete try { System.Diagnostics.Debug.WriteLine($"Exception occurred at {DateTime.Now}: {exc.Message}"); _server.Disconnect(); _server.Connect(_serverConnectionString); _connectionTime = DateTime.Now; } catch { _timer.Enabled = false; MessageBox.Show($"Error: {exc.Message}", "AS PerfMon", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }