Main Site Documentation

Timer help


hello, i want to create a timer during which a program is going to work, i have the beginning of my program :

 const int TicksPerMicrosecond = (int)TimeSpan.TicksPerMillisecond / 1000;

long startTime = System.DateTime.Now.Ticks;
int ticks = (int)(System.DateTime.Now.Ticks - startTime)>>1;

int microSeconds = ticks / TicksPerMicrosecond;
int Seconds =  microSeconds*1000 000;

and i want to create a Timer lasting “Seconds”, and reuse it several times but with different values of “Seconds”, can you help me please, because after reading tuto and others I still do not understand how to create a timer.


If you create a timer event you can un hook it and re define it.

GT.timer mytimer += new timer (1000)

And then to in hook use something like this.

mytimer -= 

You can the. Re define the timer length and re subscribe.

I’m not at my machine so this is just from memory so just use it as a very rough guide. I’ve used this in the past

Search google for un subscribing timer events.


you could simply use a timer that runs every second and dispatch different tasks after different numbers of seconds - a simple dispatcher. Increment a counter each time in the timer, and run an action if your tolerance is met.

But it all depends on how you’re intending to use it.

Are you using Gadgeteer?

What don’t you understand from the tutorial?


The way to use the timer is as follows:

GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
            timer.Tick += OneSecondTimerTick;

        void OneSecondTimerTick(GT.Timer timer)


ok, i am going to test


finally i found another solution :

startTime2 = System.DateTime.Now.Ticks; //début chrono3

                    ticks2 = (int)(System.DateTime.Now.Ticks - startTime2) >> 1;

                    microSeconds2 = ticks / TicksPerMicrosecond;

                    while (microSeconds2 < microSeconds)
                        ticks2 = (int)(System.DateTime.Now.Ticks - startTime2) >> 1;
                        microSeconds2 = ticks / TicksPerMicrosecond;

thx, for help