I have an application that requires the executing of a relatively slow (15-30 second) task after launching (importing to core data). I'm looking for a good way to execute the task without causing the interface to appear slugish or frozen. I've tried:
performselectorinbackground to try to speed up the processHowever, neither lead to a significant improvement. Any ideas?
Chunking up the import into short operations and adding them to the main NSOperationQueue
[my emphasis]
If you put the operations on the main queue they will run on the main thread and impact the UI. You should create a new queue, set the maximum concurrency to 1 and then just add all the operations.
Of course, on most iDevices there's only one CPU core so you might still see issues but if your queue is not using the main thread, fiddling with the operation's thread priority might help.
If you are trying to prevent the interface from freezing, you are going to need to use a background thread. You could use performSelectorInBackground or you could use [NSThread detachThreadSelector:. However these will not actually speed up the process, they simply free up your main thread to do other stuff. If you do decide to use a second thread you may want to read about it first if you haven't used it before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With