How to change output dynamically in C#?

Hi,
I’m trying to create a component that will change the value from its initial value when it checks for the existence of a file.

However, even if it can confirm the existence of the file, the next value is not displayed in a panel.

When I reconnect the output panel again, the correct value are displayed.

Is the component I’m trying to create can’t be achieved without change input forcibly, like “Read File” component?

Please tell me if you know something.
Thank you.

namespace WaitTest
{
    public class WaitTestComponent : GH_Component
    {
        public WaitTestComponent()
          : base("WaitTest", "WaitTest",
              "waittest",
              "testcomponent", "test6")
        {
        }


        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
        {
            pManager.AddNumberParameter("in", "in", "in", GH_ParamAccess.item);
        }

        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {
            pManager.AddNumberParameter("out", "out", "out", GH_ParamAccess.item);
        }

        protected override async void SolveInstance(IGH_DataAccess DA)
        {
            GH_Document gh_d = OnPingDocument();
            string ghpath = Path.GetDirectoryName(gh_d.FilePath);
            string varinfo = ghpath + "checkfile.txt";

            double num = 11.11;
            DA.SetData(0, num);

            while (!File.Exists(varinfo))
            {
                await Task.Delay(1);
            }

            double num2 = 99.99;

            Params.Output[0].ClearData();

            DA.SetData(0, num2);
        }

        protected override System.Drawing.Bitmap Icon => null;

        public override Guid ComponentGuid => new Guid("72ba3208-7235-483c-b4b8-30aa26177a26");
    }
}
1 Like

Are you trying to have your component actively watch a directory until a file is created?
Maybe try the ScheduleSolution and use regular synchronous call.

I’m not well versed in async methods but I think once you decouple the SolveInstance from GH canvas, you’ll have to call ExpireSolution somewhere.

1 Like

Thank you for your advice!
I can made what I needed.
Thank you so much.

nay,i meet the same question(use await),can you show me how to solve that?
thank you very much.