I am trying to schedule NSTimer on a separate thread and this is how i am doing it.
-(void) startSpinner {
#ifdef DEBUG_MODE
NSLog(@"Starting Spinner...");
#endif
self.spinnerThread = [[[NSThread alloc] initWithTarget:self selector:@selector(scheduleSpinner) object:nil] autorelease];
[spinnerThread start];
}
-(void) scheduleSpinner {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTimer *_spinTimer = [NSTimer scheduledTimerWithTimeInterval:SPIN_FIRE_INTERVAL target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:_spinTimer forMode:NSRunLoopCommonModes];
[runLoop addTimer:_spinTimer forMode:UITrackingRunLoopMode];
[runLoop run];
[pool release];
}
timerFireMethod spins my spinner and when a button is pressed (stop button), i invalidate the timer and exit the thread in this method. I do a polling here if spin button is pressed.
The problem is, my timerFireMethod gets called properly for the first time. Spinner spins for first time. But when i stop my spinner and start it again, spinner doesn't spins. The logs say that second time my "startSpinner" method gets called but "timerFireMethod" method is not called.
The worse is, the spinner works 5-6 times on simulator, 1 times on 2g device, 4-5 times on latest ipod. Its random.
How does this basically work? What could be the problem?