I’m polling a router from an iPhone. The timer only fires every 60 seconds. I’m starting the timer in ViewDidLoad and leaving it on.
There’s a flag pollingON initially set FALSE.
When the timer fires, it calls myTimerFiredMethod, which then checks,
if (self.pollingON) {
self.pollingON = FALSE ;
// run the polling code
self.pollingON = TRUE ;
}
Aside from wasting a nanosecond or two of CPU time, anything wrong with this practice?
A timer that is running although not in use, is a waste of battery life. It’s also a strange design pattern, running a timer without a cause.
Also if you turn on Polling, at worst you will have to wait almost 60 seconds before an update.
I would not recommend implementing it that way. Instead, invalidate the timer when polling is turned off and create a new timer when polling is turned on.