我有点不确定如何做到这一点:
我启动了一个在我的应用程序“生命”期间运行的“工作线程”。
[NSThread detachNewThreadSelector:@selector(updateModel) toTarget:self withObject:nil];
然后
- (void) updateModel {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
BackgroundUpdate *update = [[BackgroundUpdate alloc] initWithTimerInterval:5];
[[NSRunLoop currentRunLoop] run]; //keeps it going 'forever'
[update release];
[pool release];
}
现在线程每 5 秒“唤醒”一次(initWithTimerInterval)以查看它是否可以执行任何任务。BackGroundUpdate 类中的所有任务现在只是时间相关的。我想要一些“事件相关”的。例如,我想从我的主线程调用背景对象并告诉它“speedUp”、“slowDown”、“reset”或对象上的任何方法。
为此,我想我需要类似performSelectorOnThread
但如何获取对 NSthread 和背景对象的引用?