Trigger ScheduleSolution with Numberslider and store expired solutions

Hi Guys

I am trying to program a genetic algorithm and for that I want a C# Component to randomly change a numberslider which changes some other fitness values. This basically works with this simplified code:

private void RunScript(bool Run, List<Point3d> Phenotype, double Fitness_Area, double Fitness_Ratio, double Fitness_Boarder, object Genes, int Combinations, ref object A, ref object B)
  {
    if(Run)
    {
      int population = 3;
      List<List<Point3d>> phenotypes = new List<List<Point3d>>(); // list to store all the phenotypes
      
      var input = Component.Params.Input[5].Sources[0];
      ghn = input as Grasshopper.Kernel.Special.GH_NumberSlider;
      if (ghn != null)
      {
        if (!expired)
        {
          GrasshopperDocument.ScheduleSolution(10, callback);
        }
        else
        {
          expired = false;
          //Maincode:
          A = Phenotype;
          B = phenotypes;
          //
        }
      }
    }else{
      A = null;
      B = null;
    }
  }

  // <Custom additional code> 
  public bool expired = false;
  public Grasshopper.Kernel.Special.GH_NumberSlider ghn = null;

  private void callback(GH_Document document)
  {
    Random r = new Random();
    int k = r.Next((int) Math.Ceiling(ghn.Slider.Minimum), (int) Math.Ceiling(ghn.Slider.Maximum));
    ghn.SetSliderValue(k);
    expired = true;
    this.Component.ExpireSolution(true);
  }

but now for example with population 3 want i am trying to do is to trigger this event 3 times which would result in 3 different Phenotypes which should all be stored in lets say a variable B. But I am struggling with storing expired solutions. What would be the right approach here?

Thank you in advance!

I was able to now run the number slider multiple times with the expected behaviour. But I am still not able to store the expired solutions. Here how it looks like:

private void RunScript(bool Run, List<Point3d> Phenotype, double Fitness_Area, double Fitness_Ratio, double Fitness_Boarder, object Genes, int Combinations, ref object A, ref object B)
  {
    if(Run)
    {
      int population = 3;
      List<List<Point3d>> phenotypes = new List<List<Point3d>>(); // list to store all the phenotypes

      var input = Component.Params.Input[5].Sources[0];
      ghn = input as Grasshopper.Kernel.Special.GH_NumberSlider;
      if (ghn != null)
      {
        if (!expired)
        {
          // schedule a solution for each individual in the population
          for (int i = 0; i < population; i++)
          {
            GrasshopperDocument.ScheduleSolution(10, callback);
          }
        }
        else
        {
          expired = false;
          // add the new phenotype to the list
          phenotypes.Add(Phenotype);
          // check if we've reached the desired population size
          A = Phenotype;
          if (phenotypes.Count == population)
          {
            B = phenotypes;
          }
        }
      }
    }else{
      A = null;
      B = null;
    }

  }

  // <Custom additional code> 
  public bool expired = false;
  public Grasshopper.Kernel.Special.GH_NumberSlider ghn = null;

  private void callback(GH_Document document)
  {
    Random r = new Random();
    int k = r.Next((int) Math.Ceiling(ghn.Slider.Minimum), (int) Math.Ceiling(ghn.Slider.Maximum));
    ghn.SetSliderValue(k);
    expired = true;
    this.Component.ExpireSolution(true);
  }
  // </Custom additional code> 
}