views:

77

answers:

2

I know this is a wack question, but it is valid to performSelectorInBackground: on an iPhone apps' main thread? I am aware of performSelectorOnMainThread: but I was just wondering if performSelectorInBackground: can also be used on the main thread. My understanding is it cannot, because performSelectorInBackground: spawns a new thread each time.

+2  A: 

performSelectorInBackground: essentially spawns a new thread, then performs the desired selector on that thread.

So, no it does not execute on the main thread. Ever.

I think that using performSelector:withObject:afterDelay: without a delay would be appropriate for your situation, because that does perform the selector on the main thread, except that it's performed in the next iteration of the current run loop:

[self performSelector:@selector(someMethod) withObject:nil afterDelay:0];
Jacob Relkin
A: 

That works, thanks!

James