// Group all the background methods in one place were it's easier to find
        #region BackGroundRegion

        public void bgw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            // we cast the sender as being the thing that invokes this method as being a background worker
            BackgroundWorker bw = sender as BackgroundWorker;

            // used to extract the name of the sort engine name from the argument e.Argument
            string SortEngineName = (string)e.Argument;

            Type type = Type.GetType("SortingAlgorithmVisualizer." + SortEngineName);

            var constructor = type.GetConstructors();

            try
            {
                ISortEngine se = (ISortEngine)constructor[0].Invoke(new object[] { unsortedArray, graphicsPanel, Graphics.Height });

                // while the sorting process has not been finished or cancelled we will execute the NextStep method to keep going
                while (!se.isSorted() && (!executionThread.CancellationPending))
                {
                    se.NextStep();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw             = sender as BackgroundWorker;
            string           SortEngineName = (string)e.Argument;
            Type             type           = Type.GetType("SortVisualizer." + SortEngineName);
            var ctors = type.GetConstructors();
            //try
            //{
            ISortEngine se = (ISortEngine)ctors[0].Invoke(new object[] { theArray, g, panel1.Height });

            while (!se.IsSorted())
            {
                se.NextStep();
            }
            //} catch (Exception ex)
            //{

            //}
        }
Example #3
0
        public void bgw_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker bw             = sender as BackgroundWorker;
            string           SortEngineName = (string)e.Argument;
            Type             type           = Type.GetType("SortVisualizer." + SortEngineName);
            var ctors = type.GetConstructors();

            try
            {
                ISortEngine se = (ISortEngine)ctors[0].Invoke(new object[] { TheArray, g, panel1.Height });
                while (!se.IsSorted() && (!bgw.CancellationPending))
                {
                    se.NextStep();
                }
            }
            catch (Exception ex)
            {
            }
        }