Re: Threading Question
Re: Threading Question
- Subject: Re: Threading Question
- From: Ryan Britton <email@hidden>
- Date: Mon, 24 Oct 2005 19:09:41 -0700
Try performselectorOnMainThread:withObject:waitUntilDone:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSObject.html#//apple_ref/doc/uid/20000050-CJBEHAEF
Just have the delegate method call a finishing method using that.
On Oct 24, 2005, at 6:56 PM, Jonah Horowitz wrote:
I've been going over the documentation on threads under cocoa. I've
looked at both the SimpleThreads and TrivialThreads sample projects.
I have one main "controller" thread that manages everything and it
spawns two worker threads using the "+connectWithPorts" function in
the
sample code.
I've pasted the snippet here:
+ (void)connectWithPorts:(NSArray *)portArray
{
NSLog(@"ConnectWithPorts Called thread id = %d",[NSThread
currentThread]);
NSAutoreleasePool *pool;
Getter *getterObject;
NSConnection *connectionToStufferController;
pool = [[NSAutoreleasePool alloc] init];
connectionToStufferController = [NSConnection
connectionWithReceivePort:[portArray objectAtIndex:3]
sendPort:[portArray objectAtIndex:2]];
getterObject = [[self alloc] init];
[[portArray objectAtIndex:6] unlock];
[ ((StufferController *)[connectionToStufferController rootProxy])
setGetterServer:getterObject];
[getterObject release];
[[NSRunLoop currentRunLoop] run];
[pool release];
return;
}
I've had no problems whatsoever calling functions in my worker
threads,
but I can't figure out how to communicate from my worker threads back
to the controller thread when the controller didn't initiate the
coversation.
I'm using NSURLDownload to retrieve a file and when it completes the
download it calls a downloadDidFinish delegate in my worker thread.
How can my worker thread call my controller thread to let it know that
the download is complete.
I've tried moving the NSConnection up out of the connectWithPorts and
into the class implementation, but that seems to crash the program
when
connectWithPorts is called.
I'm totally lost and I've been banging at this for hours. Any help
would be greatly appreciated.
Thanks,
Jonah Horowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden