Help with Timer
Help with Timer
- Subject: Help with Timer
- From: Ted Lowery <email@hidden>
- Date: Thu, 2 Jan 2003 00:05:28 -0500
Hi all-
I'm trying to create a process that will run periodically. I have the
process running in a separate thread, so that it doesn't block the
interface. It does some network accesses, and can take several seconds
to complete.
I've created a timer which I invalidate after it fires, and then I wish
to re-establish it after the thread completes. However, re-creating
the timer within the thread (and a separate NSAutoReleasePool) it never
fires. See code below...
- (void)awakeFromNib
{
forecast = [[Forecast alloc] init];
timer = [[NSTimer scheduledTimerWithTimeInterval:10 //seconds
target:self
selector:@selector(update:)
userInfo:nil
repeats:NO] retain];
// [NSThread detachNewThreadSelector:@selector(updateThread:)
toTarget:self withObject:self];
}
- (void)update:(NSTimer*)aTimer
{
[timer invalidate];
[timer release];
[NSThread detachNewThreadSelector:@selector(updateThread:)
toTarget:self withObject:self];
// if I re-establish the timer here, it works, but of course, it
fires 10 seconds after the original firing, not 10 seconds after the
thread completes.
timer = [[NSTimer scheduledTimerWithTimeInterval:10 //seconds
target:self
selector:@selector(update:)
userInfo:nil
repeats:NO] retain];
}
- (void)updateThread:(id)sender
{
NSAutoreleasePool* subpool = [[NSAutoreleasePool alloc] init];
[forecast update];
// if I re-establish the timer here, it is created but never fires.
timer = [[NSTimer scheduledTimerWithTimeInterval:10 //seconds
target:self
selector:@selector(update:)
userInfo:nil
repeats:NO] retain];
[subpool release];
}
Any ideas?
Thanks, Ted
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.