• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sending image from separate thread back to AppController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Sending image from separate thread back to AppController
      • From: Shaun Wexler <email@hidden>
References: 
 >Sending image from separate thread back to AppController (From: Andrew Duncan <email@hidden>)

  • Prev by Date: Re: Is there such a thing as a global constant (string) in obj-c?
  • Next by Date: Re: How to disable Apple's Bug Report Dialog when application crash?
  • Previous by thread: Re: Sending image from separate thread back to AppController
  • Next by thread: Re: Sending image from separate thread back to AppController
  • Index(es):
    • Date
    • Thread