Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would NSTImer events block the main thread?

Tags:

iphone

nstimer

When we use a NSTimer, once the call back is called after the mentioned interval, does the UI would be blocked?

like image 392
RK- Avatar asked May 10 '11 05:05

RK-


1 Answers

That depends. Most of the time, this won't be a problem.

If, however, both of the following criteria are met, an NSTimer will block the UI thread:

  1. The timer is scheduled on the NSRunLoop of the main thread. This will be the case whenever you created it by calling one of NStimer's scheduledTimerWith... class-methods on the main thread.
  2. The method, which is called when the timer fires, performs "lengthy" tasks. Things like synchronously performed fetches/url-requests come to mind...
like image 78
danyowdee Avatar answered Oct 27 '22 00:10

danyowdee