A Problem about cannot immediately "Close" Rhino

I am writing a c# component with System.Threading.Timer,just output a number increasinly with time.

but when i close rhino,i notice the “rhino” will exist in task manager (figure below)for several minutes then disappear instead of disappear immediately:

so please help, thank you very much!
this is code:
Timer.cs (3.2 KB)

I guess you need to check if Grasshopper.Instances.ActiveCanvas.Document is null or not:

if(Grasshopper.Instances.ActiveCanvas.Document != null)
  Grasshopper.Instances.ActiveCanvas.Document.ScheduleSolution(1, UpdateSetData);

or you can use null-conditional invocation:

Grasshopper.Instances.ActiveCanvas.Document?.ScheduleSolution(1, UpdateSetData);

Here is the edited code:

private void Add(object o)
{
 if (_nowTime < 1)
    _nowTime += _step;
 else
    _nowTime = 0;
 var doc = OnPingDocument();
 if (doc == null) return;
 while (doc.SolutionDepth != 0 || doc.SolutionState != GH_ProcessStep.PostProcess) { }
 Grasshopper.Instances.ActiveCanvas.Document?.ScheduleSolution(1, UpdateSetData);
}

AutoSliderComponent.cs (2.1 KB)

P.S I’m not sure why you don’t simply use OnPingDocument() instead:

doc.ScheduleSolution(1, UpdateSetData);
2 Likes

Thank you Mahdiy
i have tried your code,and i found ,if closing the gh first,then close rhino,you can see: rhino in task manager will still be exist for several minutes.