Re: Making a Window Class Invocable from Any Thread
Re: Making a Window Class Invocable from Any Thread
- Subject: Re: Making a Window Class Invocable from Any Thread
- From: Chris Hanson <email@hidden>
- Date: Tue, 04 Nov 2008 22:29:20 -0800
On Nov 4, 2008, at 2:22 PM, Jerry Krinock wrote:
I have a class which programatically creates and manipulates an
alert window, like NSAlert except it's capable of much more. It
exposes about 55 methods, doing stuff like like -setTitle:, -
setButtonTitle:, -setProgressAmount:, -removeAllSubviews, -
setPopupTitles:, setIconStyle: etc., etc.
Now that I'm learning the coolness of NSOperation, I'd like to be
able to invoke these methods from any thread (any NSOperation).
I'd actually caution you against this. Keep your processing distinct
from your user interface, don't mix the two. Use some form of
intermediate "status" object to pass information back to your main
thread for presentation to the user, rather than trying to interact
with the user from multiple threads at once.
Otherwise you'll wind up doing one of two things:
(1) Serializing everything as a side effect of attempting to keep
interaction with the user safe; or,
(2) Dealing regularly with hard-to-address bugs that are ultimately
due to multiple threads interacting with the same data without correct
locking.
By keeping the logic that operates on your data distinct from your
user interface, you can much more easily scale your logic along with
the user's hardware, and keep debugging of both your UI and logic
straightforward.
-- Chris
_______________________________________________
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