Main Site Documentation

Fez domino Timer


#1

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).


#2

Take a look here:


#3

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)?


#4

Post your code here.


#5


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....
}



#6

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.