iosdevnyc
iosdevnyc

Reputation: 1871

Performing Tasks in the background using NSThread

I want to have a background thread that will check for updates on the server every 5 minutes and process that data. Should I use NSThread to detach a new thread and run an infinite loop and sleep that loop for every 5 minutes? and where should the thread start from, app delegate?

Is there a better option?

Upvotes: 0

Views: 798

Answers (1)

highlycaffeinated
highlycaffeinated

Reputation: 19867

Create an NSThread like you mentioned, but instead of having an infinite loop with sleeps, you'd be better off using an NSTimer. You can initialize it with timerWithTimeInterval:invocation:repeats: and then schedule it on the run loop your background thread.

Upvotes: 4

Related Questions