开发者

performSelectorInBackground: on main thread

开发者 https://www.devze.com 2023-01-15 15:05 出处:网络
I 开发者_C百科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 perf

I 开发者_C百科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.


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号