eugene
eugene

Reputation: 41665

(iphone) start timer from background thread?

I create a timer with [NSTimer scheduledTimerWithTimerInterval:target:selector:...] from a background thread
It seems the timer created from a background thread doesn't call the selector given as the argument.

Is there something special I need to run a timer from background thread?
Thank you

Here's the sequence

performSelectorInBackground: pushViewController

from the viewController's init sequence,

I alloc a timer with the above method.  

and the timer selector won't get called.

Upvotes: 0

Views: 1031

Answers (1)

occulus
occulus

Reputation: 17014

You should only do things to the UI - like pushing view controllers and changing UI items - from the main thread. If you don't, things break, as you can see.

See the Cocoa Fundamentals Guide section titled "Are the Cocoa Frameworks Thread Safe?": it says "All UIKit objects should be used on the main thread only."

Original answer

There's nothing special needed. The selector will get called on the thread you did the scheduleTimer call from.

Upvotes: 1

Related Questions