• 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: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?


  • Subject: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • From: Gilles Celli <email@hidden>
  • Date: Fri, 10 Feb 2012 22:25:07 +0100

Opening the ASCII file can take up to 15-20 sec ( > 150MB), so I made some changes as you suggested by moving the progressWindowController  alloc/init before the allocation of asciiFileContents...
And you're right I should have put addWindowController: in makeWindowController....

This makes the opening of the file a little more responsive (clicking the button) but not really what I expect...

>Never blindly assign to error pointers. Check the caller is actually interested in receiving an error first.
Which caller do you mean ?

Maybe the way to go is to use a new detached thread only for the progress window, or to use Kyle's approach by using NSOperationQueue..

Of course if you guys have any other suggestions they will be greatly appreciated :-)

Gilles


On 10 févr. 2012, at 17:08, Mike Abdullah wrote:

>> I'm sure I'm doing something wrong here :-(
>>
>> Any clues ?
>
> Yep, here we go:
>
> On 10 Feb 2012, at 15:28, Gilles Celli wrote:
>
>> In my NSDocument readFromURL:ofType:error: method it init's a progressLoading WindowController (which shows up the window with progress bar and Cancel button).
>> In my progressLoadingWC I have a BOOL cancelLoadingFlag which is checked in readFromURL method…however nothing seems to happen if I call NSError…the document is still opened...
>>
>> Also opening the file and trying to click the button is nearly impossible since it slows down heavily. Here's an excerpt of my code
>>
>> -(BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
>> {
>>   	asciiFileContents = [[NSString alloc] initWithContentsOfURL:absoluteURL
>>                                                    encoding:NSISOLatin1StringEncoding error:outError];
>
> OK, good, you're grabbing file contents on the worker thread. How long does this typically take? Why not show your progress display before this?
>
>>   if (!progressLoadingWindowController)
>>   {
>>       progressLoadingWindowController = [[ProgressLoadingWindowController alloc] init];
>>       [[progressLoadingWindowController fileNameOutlet] setStringValue:[absoluteURL lastPathComponent]];
>>       [[progressLoadingWindowController loadProgressBar] setUsesThreadedAnimation:YES];
>>       [[progressLoadingWindowController loadProgressBar] startAnimation:self];
>>
>>   }
>
> Don't do this. AppKit is not thread safe. Creating a window controller on a secondary thread is not supported.
>>
>>   // Display the progressLoading window
>>   [progressLoadingWindowController showWindow:self];
>>
>>   if ( [progressLoadingWindowController cancelLoadingFlag] )
>>   {
>>       NSLog(@"User cancelled opening...");
>>
>>       *outError = [NSError errorWithDomain:NSCocoaErrorDomain
>>                                       code:NSUserCancelledError userInfo:nil];
>
> Never blindly assign to error pointers. Check the caller is actually interested in receiving an error first.
>>   }
>>
>>   myDocWindowController = [[TsoftViewerWindowController alloc] initWithTsfFileString:asciiFileContents];
>
> Or is it this line of code that takes a long time to run? If so, what's it doing?
>>
>> 	[self addWindowController:myDocWindowController];
>
> Furthermore, it is not this method's job to create the UI. That should be done in -makeWindowControllers instead.
>>
>> 	[asciiFileContents release];
>>
>>
>>   return YES;
>>
>> }


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
      • From: Mike Abdullah <email@hidden>
References: 
 >How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Gilles Celli <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Kyle Sluder <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Gilles Celli <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Mike Abdullah <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Gilles Celli <email@hidden>)
 >Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ? (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: drawing 1 bit images, and image resolution
  • Next by Date: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Previous by thread: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Next by thread: Re: How to cancel a loading document in NSDocument's readFromURL:ofType:error method ?
  • Index(es):
    • Date
    • Thread