• 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
Allowing cancel and progress but not updating display
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Allowing cancel and progress but not updating display


  • Subject: Allowing cancel and progress but not updating display
  • From: Kevin Hoctor <email@hidden>
  • Date: Sat, 10 Mar 2007 10:59:31 -0600

I have an import routine that works most of the time, but will occasionally fail with the following errors:

2007-03-10 09:53:05.140 MoneyWell[4620] *** Assertion failure in - [NSOutlineView _expandItemEntry:expandChildren:startLevel:](), TableView.subproj/NSOutlineView.m:592
2007-03-10 09:53:05.140 MoneyWell[4620] Invalid parameter not satisfying: itemEntry->childrenInfo==NULL


I am using a separate thread to import the file into my Core Data database that kicks off by the user initiating the importQIF command:

- (IBAction)importQIF:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
NSArray *fileTypes = [NSArray arrayWithObject:@"qif"];
[panel beginSheetForDirectory:nil file:nil types:fileTypes modalForWindow:[self windowForSheet] modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
}


- (void)openPanelDidEnd:(NSOpenPanel *)openPanel returnCode:(int) returnCode contextInfo:(void *)contextInfo {
if (returnCode != NSOKButton)
return;
[openPanel close];
[NSApp beginSheet:progressPanel modalForWindow:[self windowForSheet] modalDelegate:self didEndSelector:nil contextInfo:NULL];
[progressIndicator setUsesThreadedAnimation:YES];
[progressIndicator setIndeterminate:YES];
[progressIndicator startAnimation:self];
[NSThread detachNewThreadSelector:@selector (importQIFThreadedUsingFile:) toTarget:self withObject:[openPanel filename]];
}


- (void)importQIFThreadedUsingFile:(id)object
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	[self importQIFUsingFile:object];
    [pool release];
}

- (void)importQIFUsingFile:(NSString *)filename
{
cancelImport = NO;
NSArray *transactions = [[NSData dataWithContentsOfFile:filename] transactionGroups];
[progressIndicator setIndeterminate:NO];
[progressIndicator setMaxValue:[transactions count]];
[progressIndicator setDoubleValue:0.0];
[progressIndicator display];
// ready core data objects for import
// <snip>
while (!cancelImport && (transaction = [transactionEnum nextObject])) {
[progressIndicator incrementBy:1.0];
[progressIndicator display];
// parse the file and add objects to the managedObjectContext
// <snip>
}
if (cancelImport)
[managedObjectContext rollback];
else
[managedObjectContext processPendingChanges];


	[NSApp endSheet:progressPanel];
	[progressPanel close];
}

- (IBAction)cancelQIFImport:(id)sender
{
[cancelButton setEnabled:NO];
cancelImport = YES;
}

All this works well when the stars align. I think the problem is that my UI is updating as the import is happening and I'm getting threading errors. I either need a way to keep my controllers from updating during this process or I need a single thread method that allows me to update the progress panel and allow the user to cancel the process. My experiments with detaching/reattaching bindings programatically have failed (and looked ugly anyway). Is there a modal way to do this?


Peace,

Kevin Hoctor
email@hidden
No Thirst Software LLC
http://nothirst.com


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Allowing cancel and progress but not updating display
      • From: Andrew Madsen <email@hidden>
  • Prev by Date: Re: Core Data: combining IB & code-based filter predicates
  • Next by Date: Re: Core Data and Undo action names
  • Previous by thread: Re: Core Data and Undo action names
  • Next by thread: Re: Allowing cancel and progress but not updating display
  • Index(es):
    • Date
    • Thread