Internalize Timer in C# - Simple Counter

Thank you. The code you refer to using ‘Component.ExpireSolution()’ looks similar to code posted in this thread above, including the bit from @dharman that I modified. The problem I have with it is that there’s no way to specify a delay interval?

It’s nice to be able to start/stop the timer without double-clicking the Timer component but looping as fast as possible doesn’t suite my needs. The changes I made to use a “sticky” counter make the Python only a counter, not a timer.

I found a different version of the same idea by @TomTom here, in C#, but unfortunately it doesn’t have a ‘Reset’ input:

simple_counter

A Simple Counter component that is absurdly simple indeed, if you ignore all the hidden overhead:

public class Script_Instance : GH_ScriptInstance
{
#region Utility functions
#region Members

  /**/
  private void RunScript(ref object A)
  {
    _counter++;
    A = _counter;
  }

  // <Custom additional code> 
  int _counter = 0;
  // </Custom additional code> 
}

What got me started on this was a piece of code someone posted recently that used a Timer to trigger a Data Recorder that fed a Mass Addition component to get a count value!!! Completely ABSURD, of course, but when I looked for alternatives, it’s surprisingly difficult to find a GH “best practice”.for using a timer/counter?

Can you speculate on which method, using a specified interval, has the least computational overhead? Thank you.