Keep a reference to an NSThread around and message its objects?

Posted by RickiG on Stack Overflow See other posts from Stack Overflow or by RickiG
Published on 2010-04-27T10:01:37Z Indexed on 2010/04/27 10:03 UTC
Read the original article Hit count: 273

Filed under:

Hi

I am a bit uncertain on how to do this:

I start a "worker-thread" that runs for the duration of my apps "life".

[NSThread detachNewThreadSelector:@selector(updateModel) toTarget:self withObject:nil];

then

- (void) updateModel {

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    BackgroundUpdate *update = [[BackgroundUpdate alloc] initWithTimerInterval:5];
    [[NSRunLoop currentRunLoop] run];   //keeps it going 'forever'
    [update release];
    [pool release];
}

Now the thread "wakes" up every 5 seconds(initWithTimerInterval) to see if there are any tasks it can do. All the tasks in the BackGroundUpdate Class are only time dependent for now. I would like to have a few that were "event dependent". e.g. I would like to call the Background Object from my main thread and tell it to "speedUp", "slowDown", "reset" or any method on the object.

To do this I guess I need something like performSelectorOnThread but how to get a reference to the NSthread and the Background Object?

© Stack Overflow or respective owner

Related posts about nsthread