Simple example of threading
Simple example of threading
- Subject: Simple example of threading
- From: Steve Palmer <email@hidden>
- Date: Wed, 11 Feb 2004 04:32:05 +0000
As part of building a progress dialog, I need to kick off a thread in
the same class and have that thread communicate back to the class to
update the UI. From reading the Apple docs and other examples, I need
to use NSConnection for this. However the examples given all seem to do
more than what I need. I just need to have a simple way to call just
one function on the main thread in the same class to update the UI -
nothing else.
In the code that is called once the window is displayed, I have:
-(void)windowDidLoad
{
NSPort *port1 = [NSPort port];
NSPort *port2 = [NSPort port];
NSArray *portArray;
kitConnection = [[NSConnection alloc] initWithReceivePort:port1
sendPort:port2];
[kitConnection setRootObject:self];
// Ports switched here.
portArray = [NSArray arrayWithObjects:port2, port1, nil];
[NSThread detachNewThreadSelector:@selector(workerThread:)
toTarget:self withObject:portArray];
}
Here's what I have so far in the workerThread function:
-(void)workerThread:(NSArray *)portArray
{
NSConnection * serverConnection;
serverConnection = [NSConnection
connectionWithReceivePort:[portArray objectAtIndex:0]
sendPort:[portArray objectAtIndex:1]];
...
}
At this point I'm stuck. I want to call:
-(void)updateProgress:(NSString *)progressInfo
progressValue:(int)progressValue
{
...
}
but I'm at loss as how to get from serverConnection to this function.
Any clues?
- Steve
_______________________________________________
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.