• 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: j o a r <email@hidden>
  • Date: Tue, 20 Jul 2004 23:57:46 +0200

On 2004-07-20, at 22.44, Andrew Duncan wrote:

> My AppController creates a new thread (call it Thread2), which runs
> and, in its own good time, creates an NSImage. Now I want to tell the
> main (UI) thread to display this image. Of course, Thread2 knows
> nothing about the outlets to the NSImageView, so it has to ask the
> AppController to deal with this.
>
> 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.

That would probably create problems if not everything you touch is
thread safe - including your accesses to the Cocoa libraries.

> But maybe there's some cool notification scheme or value observer or
> something in Panther that I don't know about. I'm sure this is an FAQ
> and would appreciate hearing the frequent answer.

If you can live with only supporting Panther and later, check out this
method from NSObject:

performSelectorOnMainThread:withObject:waitUntilDone:

If you need to support versions of Mac OS X earlier than Panther, you
can use ports - like Mario suggested.

j o a r

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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: Nick Zitzmann <email@hidden>
References: 
 >Sending image from separate thread back to AppController (From: Andrew Duncan <email@hidden>)

  • Prev by Date: Bug in NSImageView?
  • Next by Date: Re: From Carbon to Cocoa
  • 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