Show „Loading“ message when custom component is being loaded into the canvas

Hello,

I have developed a custom component with C#, that inside of the Solve Instance method calls another method to deserialize a JSON file, which takes some seconds to run.

At the moment, what happens is that when you drop this component into the canvas, the canvas freezes for some seconds until the Solve Instance method is completed and THEN the component appears into the canvas.

My question would be, is it possible to make the component appear in the canvas displaying a “Loading” message until the Solve Instance Method is completed?

This is how the code looks like at the moment in a simplified way:

    protected override void SolveInstance(IGH_DataAccess DA)
    {	
      If (first_run)
      {
         this.Message = “Loading Database”;
         // Here I would like to make the component appear in the canvas
         DeserializeJSONFile(); // Method that takes about 10 seconds to run
         this.Message = “”;
      }	
      // other stuff
    }

Best regards,
Diego

You can use a Windows.Forms.Form to create a splash screen, with the help of a bool gate.
So first time the component computes, it shows a non modal Form, toggles the boolean, and schedules the next solution. When the next solution actually happens, it sees the boolean, does actual work, and closes that Form

A rough mock-up here with a c# scripting component
LongComputeSplash.gh (4.4 KB)

1 Like

Hi @d.apellaniz,

You might also peek at this sample:

– Dale

2 Likes

Thank you very much. This approach works as well. I just have to figure out how to make the form look better, because the text doesn’t show properly and sometimes it doesn’t even show, but I will keep trying:

I also tried it with eto forms, but I couldn’t get the ShowModalAsync method to work.

the Eto.Forms.Form object has a method Show, which is non modal itself.

1 Like

It’s working perfectly now! Thank you very much @Will_Wang !