Mike, Kyle,

Thanks for the quick answers!
 
Yes I'm targeting Mac OS X 10.6 and later so 
canConcurrentlyReadDocumentsOfType: is a welcome addition, I completely forgot 
that.

Strangely if I put the method canConcurrentlyReadDocumentsOfType: inside my 
NSDocument I get a warning when trying to open a document (It seems to be a 
QuickLook error ?) on Mac OS X 10.7.3:

[QL] QLError(): +[QLSeamlessDocumentOpener seamlessDocumentOpenerForURL:] 
should only be called in the main thread

Now for the cancel question: If I take the more traditional approach to cancel 
the operation inside readFromURL, should I fire up a new thread to check the 
flag's status ? 

Gilles


On Feb 9, 2012, at 7:32 PM, Kyle Sluder wrote:

> On Thu, Feb 9, 2012 at 8:01 AM, Gilles Celli <[email protected]> wrote:
>> Hi,
>> 
>> I searched the mailing-list but didn't find an answer….so sorry if this was 
>> posted before:
>> 
>> I've setup a document based application which can read large ASCII data 
>> files (>150MB).
>> 
>> When opening the document the method readFromURL:ofType:error is used which 
>> then opens a small feedback window
>> showing the file name and an animated  progress bar with a "Cancel" NSButton.
> 
> If you're targeting Snow Leopard or later, you should override
> +canConcurrentlyReadDocumentsOfType: to return YES. That will cause
> -initWithContentsOfURL:ofType:error: (and therefore
> -readFromURL:ofType:error:) to execute on a background thread.
> 
> Then you get to the canceling part. The traditional approach would be
> to set a flag when the user clicks Cancel, and periodically check this
> flag from within your -readFromURL:… implementation, returning an
> NSUserCancelledError if you detect it has been set.
> 
> A more modern approach might be to use NSOperationQueue. Instead of a
> loop, -readFromURL:… would divide its work into operations and enqueue
> those on a queue. Clicking the Cancel button would enqueue an
> operation that would shut down the -readFromURL:'s operation queue and
> cause it to return an NSUserCancelledError.
> 
> --Kyle Sluder


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to