Re: NSThread call back...
Re: NSThread call back...
- Subject: Re: NSThread call back...
- From: Chris Hanson <email@hidden>
- Date: Wed, 9 Nov 2005 11:54:23 -0800
On Nov 9, 2005, at 10:50 AM, Brian O'Brien wrote:
You can pass the detacher to the thread, and then invoke on the
detacher -performSelectorOnMainThread:withObject:waitUntilDone: to
have the specified selector invoked on the detacher.
detacher is the class that constructed the thread? So like... self?
By "detacher" I mean the object that created the thread, yes. A
thread is created using +[NSThread
detachNewThreadSelector:toTarget:withObject:] so the "detacher" would
be the object that invokes that method.
This is the anObject parameter to myInstanceThreadMethod?
Yes, when I say "pass the detacher to the thread" that's what I mean.
Ok so then I save a reference to anObject and call a well know
selector on that object.
[NSThread detachNewThreadSelector:@selector
(MyInstanceThreadMethod:) toTarget:myServer withObject:self];
Your method selectors should begin with lower-case letters, per Cocoa
and Objective-C coding conventions.
- (void) MyInstanceThreadMethod:(id)anObject
{
parent = anObject;
// later on...
[parent wellKnowSelectorNameWithWellKnowParameter:10];
}
The -performSelectorOnMainThread sounds... tricky...
However, it's necessary if you want to communicate between threads.
If you don't use it, then you will be invoking your target method
within your detached thread. There is no magical association between
objects and threads; you need to take affirmative steps (such as
using a thread-safe queue, some other signaling mechanism, or -
performSelectorOnMainThread:withObject:waitUntilDone:) to communicate
between threads.
-- Chris
_______________________________________________
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