Re: Delegation across thread
Re: Delegation across thread
- Subject: Re: Delegation across thread
- From: Andre Masse <email@hidden>
- Date: Fri, 31 Oct 2008 07:40:17 -0400
Thanks a lot for your very clear explanation Michael. Looks like
performSelectorOnMainThread: will be the way to go.
Thanks again,
Andre Masse
On Oct 31, 2008, at 00:41, Michael Ash wrote:
It's important to remember that "delegate" is just a design pattern,
not a language feature. A delegate is just a defined set of messages
that you send to an object in certain situations. When it comes to
threads, they behave just like any other messages, because they are
just regular messages.
So what happens when you send a delegate message on a secondary
thread? Same thing as when you send any other message: the
corresponding method gets invoked synchronously on the same thread.
(I.e. you call it directly.)
This can be bad. If you're going to do this then your delegate needs
to be prepared to receive delegate messages on secondary threads, and
that can sometimes be annoying. Sometimes it's entirely reasonable. It
really depends on your situation. If your situation is such that it's
unreasonable, the solution is easy: just use
performSelectorOnMainThread: to ship the delegate message back to the
main thread where it can be invoked in a better place. If you want to
invoke it on some thread other than the main thread then Cocoa
provides a fair number of inter-thread communication techniques that
you can use. Ignore the fact that this is a "delegate" and just see
how and where you want to send your message.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden