我正在尝试NSTimer
在子线程中触发。我的代码基本上是这样的:
-(void) handleTimer:(NSTimer *)theTimer {
NSLog(@"timer fired");
}
-(void) startMyThread {
// If I put timer in here, right before I start my new thread, it fires.
// [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(handleTimer:) userInfo:nil repeats:NO];
[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
}
// This method is called from inside the new thread
-(void) playNote:(Note *)theNote withTemplate:(NSString *)theTemplate X:(int)x andY:(int)y {
NSLog(@"before timer");
// The timer doesn't fire in here. (But the print statements do.)
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(handleTimer:) userInfo:nil repeats:NO];
NSLog(@"after timer");
}
我真的很想(阅读:需要?)在子线程中触发计时器,因为它将用于停止播放音符(并且所有音符播放都需要在子线程中进行)。
我一定错过了NSTimer
在子线程中运行的一些东西......
过早感谢您的帮助!