iphone - Anything wrong with leaving timer on and using a flag to control execution on/off? -


i'm polling router iphone. timer fires every 60 seconds. i'm starting timer in viewdidload , leaving on.

there's flag pollingon set false.

when timer fires, calls mytimerfiredmethod, checks,

if (self.pollingon) {   self.pollingon = false ;   // run polling code   self.pollingon = true ; } 

aside wasting nanosecond or 2 of cpu time, wrong practice?

a timer running although not in use, waste of battery life. it's strange design pattern, running timer without cause.

also if turn on polling, @ worst have wait 60 seconds before update.

i not recommend implementing way. instead, invalidate timer when polling turned off , create new timer when polling turned on.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -