Re: updating NSView on separate thread
Re: updating NSView on separate thread
- Subject: Re: updating NSView on separate thread
- From: Jens Alfke <email@hidden>
- Date: Mon, 1 Feb 2010 12:56:32 -0800
On Feb 1, 2010, at 12:11 PM, Patrick Cusack wrote:
As for NSRunLoop, let me see if I understand. I have created a new
Thread with [NSThread detachNewThreadSelector:toTarget:withObject:].
The selector is a do loop that periodically calls a custom NSView's
redisplay method that invokes [NSView setNeedsDisplay:YES].
So if I understand, you are going to keep your save code on the main
thread, but spawn a background thread that periodically updates a view.
I should invoke this using performSelectorOnMainThread.
That won't work. Such requests get queued up on the main thread's
runloop and won't be serviced until the next time the runloop runs,
which will be after your save code finishes. (Unless you refactor your
save code to crank the runloop periodically, in which case you can
just put the view-redraw code there too and avoid the need for a
background thread.)
If you want to go this way you'll need to do the view updating
directly from the background thread. It sounds as though it's legal to
update the view's state, but I'm not sure it's legal to flush the
window from another thread, and without that, the view changes won't
show up onscreen.
—Jens_______________________________________________
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