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 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