Creating Number sliders Using C# component

I have written a code using the forum posts and websites to create number sliders and I will use all of them as genomes in the Galapagos. I need to change the sliders using the Galapagos to optimize a shape in terms of my fitness function. The problem is that when Galapagos changes the values in the sliders it does not make any change in the shape.

It seems that the expiration problem exists here but I do not know how to solve that. the number of sliders may change during the whole code that I have. In a solution there will be for example only 12 sliders which changing the value of them should change the shape that I am trying to optimize it.

When I am using the ExpireSolution(True) method the rhino crashes!!

Is there any recommendation to solve the problem?

Thanks

One thing that comes to mind regarding the crash is that you should make sure that you are using the ExpireSolution method correctly. This method is used to indicate that the solution has changed and needs to be recomputed. If you are using the ExpireSolution method in a loop, make sure that you are not calling it too frequently, as this could cause Rhino to crash.

If you could upload a sample file It’d be easier to help you

Thanks for the reply.
I am sharing the code that I am using in a C# component here.
I commented “onsolutionexpired(true)” command but it is crashing again.

public class Script_Instance : GH_ScriptInstance
{
private void RunScript(bool x, object y, List z, int U, int V, ref object A)
{

var x_list = new List<decimal>();

Random rnd = new Random();
if(x)
{
  if(this.Component.Params.Input[1].SourceCount > 0)
  {
    List<IGH_Param> sources = new List<IGH_Param>(this.Component.Params.Input[1].Sources);
    GrasshopperDocument.RemoveObjects(sources, false);
  }

  //instantiate  new slider
  Grasshopper.Kernel.Special.GH_NumberSlider slid = new Grasshopper.Kernel.Special.GH_NumberSlider();

  //sets up default values, and makes sure your slider doesn't crash rhino
  slid.CreateAttributes();


  for(int i = 0;i < z.Count;i++)
  {

    //number of points in each plane (U-1)*(V-1)
    int c = (U - 1) * (V - 1);

    //maximum range of the slider
    int max = ((i + 1) * c) - 1;

    //minimum range of the slider
    int min = i * c;

    //customise slider (position, ranges etc)
    int inputcount = this.Component.Params.Input[1].SourceCount;
    slid.Attributes.Pivot = new System.Drawing.PointF(this.Component.Attributes.DocObject.Attributes.Bounds.Left - slid.Attributes.Bounds.Width - 30, this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);

    //set the slider's maximum value
    slid.Slider.Maximum = max;

    //set the slider's minimum value
    slid.Slider.Minimum = min;

    //slider's decimal places
    slid.Slider.DecimalPlaces = 0;


    //set the slider's current value
    //slid.SetSliderValue(max);
    slid.Slider.Value = min;

    //slid.Slider.Value(min);

    //Add the current value of the slider to a list
    x_list.Add(slid.CurrentValue);

    //Until now, the slider is a hypothetical object.
    // This command makes it 'real' and adds it to the canvas.
    GrasshopperDocument.AddObject(slid, false);

    //Connect the new slider to this component
    this.Component.Params.Input[1].AddSource(slid);
  }

  //Solution Expired!!! :((
  //slid.OnSolutionExpired(true);
}

A = x_list;

}

Hi, though this is not exactly what you are doing, but I think this would help at least.
happynewyear.gh (444.3 KB)