This is just out of academic curiosity because I can successfully use:  
[NSThread detachNewThreadSelector: toTarget: withObject:] to do what I want.  
Nevertheless, I have been trying to do the same thing in the main Thread with 
NSTimer and something is wrong that I just cannot figure out.  So, here are 
some snippets:

In the .h file I have:   NSTimer *itsTimer;

In the .m file I have:

- (void )startTimer {
        if (!itsTimer || ![itsTimer isValid]) {
                NSTimer *theTimer;
                theTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 
target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
                itsTimer = theTimer;
        }
}

- (void )stopTimer {
        if (itsTimer && [itsTimer isValid]) {
                [itsTimer invalidate];
                itsTimer = nil;
        }
}

- (void )timerFireMethod:(NSTimer *)theTimer {
        NSLog(@"we are here");  // just to keep it simple at first
}

I call -startTimer and -stopTimer from the main Thread and the NSLog(@"we are 
here") never shows in the Console.

I did try, unsuccessfully:
                theTimer = [[NSTimer alloc] initWithFireDate:[NSDate date] 
interval:0.5 target:self selector:@selector(timerFireMethod:) userInfo:nil 
repeats:YES];
                [[NSRunLoop currentRunLoop] addTimer:theTimer 
forMode:NSDefaultRunLoopMode];
                itsTimer = theTimer

I think I have found the problem, but I would like confirmation ... the calls 
are from the main Thread, immediately followed by the display of a sheet.  I am 
trying to intercept errors while the sheet shows.  And while the sheet shows, 
all access to -timerFireMethod is temporarily halted.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to