Re: Threaded NSDocuments
Re: Threaded NSDocuments
- Subject: Re: Threaded NSDocuments
- From: Mike Davis <email@hidden>
- Date: Fri, 18 Jan 2002 21:32:27 -0500
On Friday, January 18, 2002, at 09:15 PM, cocoa-dev-
email@hidden wrote:
Date: Fri, 18 Jan 2002 19:03:43 +0000
Subject: Threaded NSDocuments
From: Ken Tabb <email@hidden>
To: Cocoa-Dev List <email@hidden>
Hi,
are the NSDocuments in a Cocoa Obj-C Document-based app threaded, i.e.
is each document its own thread? If not what would be the easiest way of
achieving this? I have a fairly CPU-intensive image processing app, and
I'd like to be able to move between / start / stop docs while one doc is
being crunched (as they're not processed in real time).
NSDocument objects are in the main application thread, normally.
If you want to process an image for a document in the background, you
can use NSThread to run a method in the document in a detached thread.
This thread can be used to do the processing you need to do and send
messages, with NSConnection, to the main thread to get it to render data
as it becomes available. NSConnection's documentation has an example of
how to set up communications between two threads. You'll want to add
some code in there to cancel the processing thread when the document
needs to be closed.
You might be able to make it a little more generic using a command
pattern, though I don't know if the processing of the image can be made
into discrete components such as... apply 8 bit filter, scale image etc.
Thanks in advance,
Ken
- - - - - - - - - -
Ken Tabb
Mac & UNIX Technical bloke (C, C++, Obj-C, Java) - Health & Human
Sciences
Machine Vision & Neural Network researcher - Computer Science Dept
University of Hertfordshire, UK
http://www.health.herts.ac.uk/ken/
Certified non-Microsoft Solution Provider