• 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: Mario Diana <email@hidden>
  • Date: Tue, 20 Jul 2004 17:25:09 -0400

On Tuesday, July 20, 2004, at 04:44 PM, 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?

You use NSConnection and NSPort objects. Check the Cocoa documentation for "Multithreading." Example code is here:

http://developer.apple.com/documentation/Cocoa/Conceptual/ Multithreading/Tasks/connections.html

Basically, in the GUI thread you create an NSConnection object, passing it two NSPorts, one for reading and one for writing. When you fire off the second thread, you pass the ports to the new thread (you're going to use them in reverse order).

When the second thread needs to communicate back to the first, it creates an NSConnection, setting the first thread's write port as its read port, and the first thread's read port as its write port. The second thread then uses the NSConnection object to get a proxy to the first thread. Send all messages to the proxy.

Go through the documentation and especially the example, and I'm sure you'll get it. It is really quite elegant.

Mario

=======================================================
Mario Diana Mobile: 845-380-8428
50 Forest Drive Home: 845-221-3989
Poughquag, NY 12570 Email: email@hidden
=======================================================
Programmer - Web development, Java, XML, LAMP, Mac OS X
=======================================================
_______________________________________________
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.


References: 
 >Sending image from separate thread back to AppController (From: Andrew Duncan <email@hidden>)

  • Prev by Date: Re: connecting the dots (two nib files)
  • Next by Date: Re: Auto enable/disable buttons...
  • Previous by thread: Sending image from separate thread back to AppController
  • Next by thread: Re: Sending image from separate thread back to AppController
  • Index(es):
    • Date
    • Thread