• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Help with Timer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Help with Timer
      • From: David Rio Vierra <email@hidden>
  • Prev by Date: [basic] retain an NSTextView object and update a window
  • Next by Date: Re: Help with Timer
  • Previous by thread: Re: [basic] retain an NSTextView object and update a window
  • Next by thread: Re: Help with Timer
  • Index(es):
    • Date
    • Thread