【问题标题】:performSelectorInBackground: on main threadperformSelectorInBackground:在主线程上
【发布时间】:2010-09-14 12:09:31
【问题描述】:
我知道这是一个古怪的问题,但是在 iPhone 应用程序的主线程上执行 SelectorInBackground: 是否有效?我知道 performSelectorOnMainThread: 但我只是想知道 performSelectorInBackground: 是否也可以在主线程上使用。我的理解是不能,因为 performSelectorInBackground: 每次都会产生一个新线程。
【问题讨论】:
标签:
iphone
multithreading
【解决方案1】:
performSelectorInBackground: 本质上是生成一个新线程,然后在该线程上执行所需的选择器。
所以,不,它不会在主线程上执行。永远。
我认为无延迟使用performSelector:withObject:afterDelay: 适合您的情况,因为 确实 在主线程上执行选择器,但它是在当前运行的下一次迭代中执行的循环:
[self performSelector:@selector(someMethod) withObject:nil afterDelay:0];