I have tried to create a Queue in which I place a long calculation. Without the Queue, my app is “frozen” until the calculation is complete.

However, my app literally crashes. So, here are some snippets where I obviously need your help:



@interface MyCalcController:NSObject {

    NSString              *opData;

    NSOperationQueue      *theQueue;

    NSInvocationOperation *theOp;

}



- (void) startQueue;

- (void) stopQueue;

- (void) calculateWorksheet:(id)data;

- (void) startCalculation;

- (void) stopCalculation;

@end



- (void) calculateWorksheet:(id)data {

    int row;

    for (row=1; row < 500; row++) {

        // long calculation here

    }

}



- (void) startQueue {

    NSLog(@"start queue");   // I see this in the debugger



    opData = @"not used data";

    theQueue = [[NSOperationQueue alloc] init];

    theOp = [[NSInvocationOperation alloc] initWithTarget:self

selector:@selector(calculateWorksheet:)

                                           object:opData];

    [theQueue addOperation:theOp];

}



- (void) stopQueue {

    NSLog(@"stop queue");   // .. but I do not see this



    [theQueue cancelAllOperations];

 // [theQueue release];   // done by [theOp release]

    [opData release];

    [theOp release];

}



- (void) startCalculation {

    [self startQueue];

}

// I also call this method from another Controller

- (void) stopCalculation {

    [self stopQueue];

}



John Love

Touch the Future! Teach!

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to