private void UpdateProgressBar() { if (this.InvokeRequired) { SafeVoidDelagate d = new SafeVoidDelagate(UpdateProgressBar); progressBar1.Invoke(d, new object[] { }); } else { this.progressBar1.Value++; } }
private void UpdateGlobalStatistics() { if (!InvokeRequired) { lock (globalStatLock) { var runs = listBox1.Items.Cast <RunInfo>(); var validRuns = runs.Where(item => item.Status == Runner.Status.Successful); if (validRuns.Count() == 0) { return; } var speeds = validRuns.Select(run => CalculateFrames(run).speed); int totalRot = validRuns.Sum(run => run.Rotations); var rotations = validRuns.Select(run => run.Rotations); List <int> numberOfRotations = new List <int>(); List <int> count = new List <int>(); for (int i = rotations.Min(); i <= rotations.Max(); i++) { numberOfRotations.Add(i); count.Add(rotations.Count(r => r == i)); } this.chart2.Series.Clear(); this.chart2.Series.Add("Rotations"); this.chart2.ChartAreas.First().AxisX.Title = "Number of rotations in single run"; this.chart2.ChartAreas.First().AxisY.Title = "Count"; this.chart2.ChartAreas.First().AxisY.Maximum = count.Max(); this.chart2.Series["Rotations"].Label = null; this.chart2.Series["Rotations"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column; for (int i = 0; i < count.Count; i++) { this.chart2.Series["Rotations"].Points.AddXY(numberOfRotations[i], count[i]); } var crashed = runs.Where(item => item.Status == Runner.Status.Crashed).Count(); double crashedd = (double)crashed / runs.Count() * 100; var allRuns = new List <float>(); foreach (var run in validRuns) { var times = run.Frames.Select(frame => frame.TimeDelta).ToList(); allRuns.AddRange(times); } textBox2.Text = $"Total rotations {totalRot} in {rotations.Count()} successful runs. {crashedd:0.00}% crashed.\r\n" + $"Median frame length from all runs {Statistics.Median(allRuns):0.00} ms, mean {Statistics.Mean(allRuns):0.00} ms"; } } else { SafeVoidDelagate d = new SafeVoidDelagate(UpdateGlobalStatistics); chart2.Invoke(d, new object[] {}); } }
private void EnableControlsSafe() { if (this.InvokeRequired) { SafeVoidDelagate d = new SafeVoidDelagate(EnableControlsSafe); listBox1.Invoke(d, new object[] { }); } else { button2.Enabled = true; numericUpDown1.Enabled = true; numericUpDown2.Enabled = true; progressBar1.Visible = false; } }