How would I put this action on a timer, so that the timer can be counting without stopping the entire code?
The hardware timers do not have much of a capacity, you use the millis function to return the current time, like in the blink without delay example in the IDE.