Refresh and Redraw without Timer Component (C#)


I would like my GH-script component to take care of its own timing. I can add a tick event and that can do some calculations, but neither the component outputs, nor the view overrides get updated. Is there a way to do that?
Also when using VS to compile an actual plugin, how to handle these updates?

I see that Kangaroo etc. handle updates on their own - just wondering what is the right way…

(David Rutten) #2

You certainly can use a timer, just be sure that from within the Tick event you expire your component (by calling ExpireSolution(true) usually) and trigger a new solution. Then, when that solution starts, your SolveInstance() method will be invoked and you can assign new outputs. Do be careful about expiring components, this must be done on the UI thread, whereas a lot of timers will raise events on some other thread.

Another approach is to schedule a solution. You can tell the document that you want another solution at some time in the future, and when that time comes around (or thereabouts) a new solution will be triggered. You will have to register a callback method with your schedule, because you will have to expire your component before this scheduled solution starts. so something along the lines of:

GH_Document doc = OnPingDocument();
if (doc != null)
private void SolutionCallback(GH_Document document)
  this.ExpireSolution(false); // `false` because a new solution is already in the works.