private void ButtonFindBest_Click(object sender, RoutedEventArgs e)
        {
            if (Solver == null)
            {
                return;
            }

            var actions = Sim.GetCraftingActions();

            Solver.Continue        = !Solver.Continue;
            ButtonFindBest.Content = Solver.Continue ? "Stop" : "Simulate";

            int taskCount       = 8;
            int chromosomeCount = 150;
            int val             = 0;

            if (int.TryParse(TextBoxTaskCount.Text, out val))
            {
                taskCount = val;
            }
            if (int.TryParse(TextBoxChromosomeCount.Text, out val))
            {
                chromosomeCount = val;
            }

            if (Solver.Continue)
            {
                int timeLimit      = 0;
                int iterationLimit = 0;

                int.TryParse(TextBoxTimeLimit.Text, out timeLimit);
                int.TryParse(TextBoxIterationLimit.Text, out iterationLimit);

                Solver.Start(taskCount, chromosomeCount, CheckBoxLeaveActions.IsChecked == true, timeLimit, iterationLimit);
                PopulationsWindow = new PopulationsWindow();
                PopulationsWindow.AddSolver(Solver);
                PopulationsWindow.Closed += (x, y) =>
                {
                    PopulationsWindow = null;
                };
                PopulationsWindow.Show();
            }
            else
            {
                if (PopulationsWindow != null && PopulationsWindow.ShowActivated)
                {
                    PopulationsWindow.Close();
                    PopulationsWindow = null;
                }
            }
        }
 private void Solver_Stopped()
 {
     try
     {
         Dispatcher.Invoke(() =>
         {
             if (PopulationsWindow != null)
             {
                 PopulationsWindow.Close();
             }
             ButtonFindBest.Content = "Simulate";
         });
     }
     catch (Exception e)
     { Debugger.Break(); }
 }