i wrote a component to do a long calculation work:
the function is :when input “true”,it output 0.516,when input “false”,it output 0.00
but you can see the picture above,the input is true,but the output is a tree data…and this output had to been shown by reconnect the component and panle.
this is the code:
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddBooleanParameter("B", "", "", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddNumberParameter("N", "", "", GH_ParamAccess.item);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected async override void SolveInstance(IGH_DataAccess DA)
{
bool b = default;
DA.GetData("B", ref b);
if (b == true)
{
double r = await GetLongtimeCaluculationAsync3();
DA.SetData("N", r);
}
else
{
DA.SetData("N", 0f);
}
//ExpireDownStreamObjects();
}
Task<double> GetLongtimeCaluculationAsync3()
{
Task<double> a = Task.Run(() =>
GetLongtimeCaluculation()
);
return a;
}
double GetLongtimeCaluculation()
{
double answer = 0;
for (int j = 0; j < 10000; j++)
{
for (int i = 0; i < 5000; i++)
{
answer = Math.Sin(i) + Math.Cos(i);
}
answer = Math.Sin(answer + 1) + Math.Cos(answer + 1);
}
return answer;
}
thank you for help!