// The only connection with the GUI.
        public int DoTheBenchmark(BackgroundWorker worker, DoWorkEventArgs workEvent, TestParameters test)
        {
            if (test.SanityTest)
            {
                this.winsole.WriteLine("\nSanity check is running!\n");
                this.SanityCheck(500);
                return 1;
            }

            Candidate.SetSelected(test.AlgoSelected);
            test.Init();

            int[] benchValues = TestParameters.TestValues;
            double workLoad = test.WorkLoad, workDone = 0;

            for (int j = 0; j < test.TestLength; j++)
            {
                int n = benchValues[j];

                foreach (Candidate cand in Candidate.Selected)
                {
                    if (worker.CancellationPending)
                    {
                        workEvent.Cancel = true;
                        return 0;
                    }

                    this.DoTest(cand, n, test.ShowFullValue, test.Verbose);

                    // Report progress as a percentage of the total task.
                    workDone += n * cand.WorkLoad;
                    var percentComplete = (int)(100 * workDone / workLoad);
                    worker.ReportProgress(System.Math.Min(100, percentComplete));
                }

                this.RelativeRanking(n);
            }
            this.UsedTime(benchValues, test.TestStart);
            this.PerformanceProfile(benchValues, test.TestStart);

            string outputDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\FactorialBenchmarks\";
            var df = new DirectoryInfo(outputDir);
            if (!df.Exists)
            {
                df = Directory.CreateDirectory(df.FullName);
            }

            var fileName = string.Format(df.FullName + "FactorialBenchmark{0}.html", DateTime.Now.ToFileTime());
            Result.ResultsToFile(fileName);
            this.winsole.WriteLine("\n\nBenchmark was saved to file \n" + fileName);
            this.winsole.WriteLine("\n\n");
            this.winsole.Flush();

            try { System.Diagnostics.Process.Start(fileName); }
            catch (System.ComponentModel.Win32Exception) { }
            catch (System.Exception) { }

            return 1;
        }
        public BenchmarkWindow()
        {
            this.InitializeComponent();
            this.InitAlgoBoxes();

            this.StepBox.SelectedItem = "2.0";
            this.test = new TestParameters(NumOfCandidates);

            this.winsole = new LoggedTextBox(this.TextBox);
            this.benchmark = new BenchmarkWorker(this.winsole);

            this.LogToFileCheckBox.IsChecked = true;
            this.winsole.LogToFile = true;

            BenchmarkApplication.PrintAppAndSysProps(this.winsole);
            this.InitializeBackgoundWorker();
        }