• 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: John Pannell <email@hidden>
  • Date: Tue, 20 Jul 2004 17:07:47 -0600

Hi Andrew-

I'm not sure I could call anything I'm doing "best practice", but I
have an app that generates an image in a thread and then places the
image in the UI (in a cell in a matrix, to be specific). The method is
part of my AppController, and is spun off into a separate thread via

[NSThread detachNewThreadSelector:@selector(addImageWithURL:)
toTarget:self withObject:myURLString];

Now, with this usage, the thread does know about the outlets to various
UI elements that the AppController knows about. So, in the method
running in the separate thread, I call

[[thePreviewView cellAtRow:row column:column] setImage:thumbImage];

where thePreviewView is an IBOutlet in my AppController's header file.
It all seems to work without a hitch. The thread performs a
calculation so that every thread is working on a unique row/column, so
there is no thread contention for UI objects.

HTH,

John

On Jul 20, 2004, at 2: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? 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.
>
> 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.
> _______________________________________________
> 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.
_______________________________________________
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: Alias Woes...
  • Next by Date: Re: Lost in Linking a Framework within the App bundle
  • 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