Re: Sending image from separate thread back to AppController
Re: Sending image from separate thread back to AppController
- Subject: Re: Sending image from separate thread back to AppController
- From: Andrew Duncan <email@hidden>
- Date: Wed, 21 Jul 2004 08:31:29 -0700
On 20 Jul, 2004, at 14:23, John C. Randolph wrote:
On Jul 20, 2004, at 1:44 PM, Andrew Duncan wrote:
What's the Best Practice for this one? First impulse is to give the
new thread a pointer back to the AppController. Then Thread2 can call
a method on the AppController, sending the image (pointer) and having
the AppController call setNeedsDisplay on the imageView.
Sounds like a job for
-performSelectorOnMainThread:withObject:waitUntilDone:.
Thanks, John (and all the other posters with good advice). For the
record, what's wrong with the naive approach I outlined? I realize that
calling the AppController would happen in Thread2, but I would think
that after the AppController calls setNeedsDisplay (still in Thread2)
that the handling of that re-display would happen in the main UI
thread. But that comes from my model of some sort of a message queue;
maybe that's not accurate?
E.g. Shaun suggested this method in the AppController:
- (void)setNewImage:(NSImage *)image
{
if (pthread_main_np()) {
[myImageView setImage:image];
} else {
[self performSelectorOnMainThread:_cmd withObject:image
waitUntilDone:NO];
}
}
which is like my top-of-the-head idea, except I omit the check for main
thread. (Very clever little pattern there, a bit like forking. Gotta
remember that one.)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.