Fez domino Timer

I’m trying to calculate a heart rate. I have the counter working but i don’t know how to create a timer. i need it to run for like 10s so that i can calculate the heart rate every 10s ( please note, my code has to be running to while its counting).

Take a look here:

the thing is that the code waits. my code stops running while it wait so how do i keep sampling the heart rate and count time ( together)?

Post your code here.



public static System.Threading.Timer _timer;

public static void Main()
{
    CreateTimer();

    while(true)
    {
         //Continue processing your inputs here, accumulating counters, etc.
    }
}


public static void CreateTimer()
{
    _timer = new System.Threading.Timer(TimerCallback, null, 10000, 10000);
}

public static void TimerCallback()
{
    //This method is called every 10 seconds....
}


OK, Almost there.

Have a class variable or property for counter. Accumulate it in the main while loop. Then in your timer callback get its value and reset the counter to zero.