Re: Multi-threaded AppKit examples?
Re: Multi-threaded AppKit examples?
- Subject: Re: Multi-threaded AppKit examples?
- From: John Hörnkvist <email@hidden>
- Date: Mon, 28 Jan 2002 14:21:07 +0100
On Monday, January 28, 2002, at 01:35 PM, Fraser Speirs wrote:
Hi,
I'm working on a cocoa app where we periodically request data from
another application (specifically, the current song in iTunes) via
Applescript. The way we do it is by invoking /usr/bin/osascript via
NSTask. This is slow and at the moment we do it in the UI thread,
leading to barely-acceptable responsiveness to the user.
I understand that I should use Distributed Objects to communicate
between the threads, but I'm kind of stuck with actually passing data
back and forth.
Well, it's one way, but it is often overkill.
If anyone has an example of computing a result in another thread and
returning it to the AppKit thread, I'd *love* to get a look at it.
Look at OmniFoundation; it contains method for scheduling things to run
in other threads.
For example:
[[OFMessageQueue mainQueue] queueSelector:@selector(setCurrentSongName:)
forObject:someObject withObject:theString];
In my own framework I use a trampoline pattern instead; I find that
somewhat easier to read:
[[someQueue queueForTarget:someObject] setCurrentSongName: theString];
[[someObject doInMainThread] setCurrentSongName: theString];
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com