PerfomSelector: withObject: afterDelay: can I set the priority to low?
Not directly. If you use performSelector:withObject:afterDelay:
, the selector is executed on the main thread , so by definition it will happen after all the current "pending" UI events have been executed, but it could be in the middle of a scroll or animation that you probably think of as one continuous event. but actually hundreds of individual ones.
However, you can achieve something like this with performSelectorInBackground:withObject:
and then call [NSThread setThreadPriority:0.01]
in the called method. Be careful - you are opening a background thread, so you cannot make any UI calls. However, this will allow you to do work on a background thread with a lower priority than the main UI thread. (Don't forget to set up the autocomplete pool, as it's on its own thread!)
a source to share
Actually, it performSelector:withObject:afterDelay:
does not have to appear in the main thread; therefore there is a separate method performSelectorOnMainThread:withObject:waitUntilDone:
. The documentation for performSelector:withObject:afterDelay:
says
Calls the receiver method on the current stream , using the default mode after the delay.
If you want to run a task in the background, you can look into +[NSThread detachNewThreadSelector:toTarget:withObject:]
which will start a new thread to complete your task and keep the UI responsive. Using a separate thread to perform a long-running task that might otherwise block your interface is generally a good idea, but it adds complexity. If you are not familiar with streams, you might get errors that don't make any sense.
In the comment above, you mentioned that you think the animation might be to blame for your UI not responding. If you are using built-in animation support (Core Animation or one of Cocoa's wrappers), the animation shouldn't make your UI irrelevant. An unresponsive UI usually means your program is doing a lot of work on the main thread before allowing the startup loop to return to serving UI events.
a source to share