private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { CurrentAlgortihm currentAlgortihm = (CurrentAlgortihm)e.Argument; try { Thread.Sleep(300); } catch (ThreadInterruptedException exception) { Console.WriteLine("Thread Interrupted" + exception); } foreach (Algorithm algorithm in Algorithms.ToArray()) { currentAlgortihm(algorithm); Window.ShuffleWhenStarted(); int[] unsortedArray = new int[Window.ArrayLength]; Array.Copy(Window.Array, unsortedArray, Window.ArrayLength); algorithm.Start(); algorithm.Sort(); algorithm.Stop(); Sleep(100); Window.RunWhenFinallySorted(); Sleep(100); Window.ResetColor(); Sleep(100); if (ShouldSave) { SortSummary summary = new SortSummary { Iterations = algorithm.Swaps, Name = algorithm.Name, SortedArray = Window.Array, UnsortedArray = unsortedArray }; SortSummaries.Add(summary); } if (Algorithms.Any()) { Algorithms.Dequeue(); if (Algorithms.Any()) { Window.ShuffleAfterSorted(); Window.Invalidate(); } } } }
private void DataGridSummary_CellClick_1(object sender, DataGridViewCellEventArgs e) { SortSummary summary = (SortSummary)dataGridSummary.CurrentRow.DataBoundItem; textBoxAlgorithmName.Text = summary.Name; textBoxDate.Text = Session.Date.ToString(); for (int i = 0; i < summary.UnsortedArray.Length; i++) { listBoxUnsorted.Items.Add(summary.UnsortedArray[i].ToString()); } for (int i = 0; i < summary.SortedArray.Length; i++) { listBoxSorted.Items.Add(summary.SortedArray[i].ToString()); } textBoxSwap.Text = summary.Iterations.ToString(); textBoxSession.Text = Session.Name; }