Unless you have a special need for timers, you can use Grand Central Dispatch.
The next fragment will execute the block after 2 seconds in a parallel default priority queue (i.e. background thread). You can change the priority of the queue if you think it is necessary, but if you do not deal with many different operations in parallel queues, by default it will be enough.
double delayInSeconds = 2.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
If you want to call it repeatedly, you can use dispatch_source_set_timer to set repetitive execution. The essence of this is below:
Wduk
source share