Reputation: 1223
My project is a calculation based criteria,where we populate list of mandatory fields from the coredata
that were first fetched through webservice.
There is an option to calculate and reset the field. Since the calculation takes much time and freezes the app, I used NSInvocationOperation
adding it to an NSOperationQueue
.
Whenever I enter "calculate" an operation is being queued and with no time if a reset it ,the app crashes and the console shows that it has crashed at [RiskModel calculate],which is calling the queued operation.
Is there any better solution to do this function
- (void)calculateRiskAutomatically {
[self.calculateOpQueue cancelAllOperations];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(calculateRiskAutomaticallyWithOperation) object:nil];
[self.calculateOpQueue addOperation:operation];
[operation release];
}
- (void)calculateRiskAutomaticallyWithOperation {
[self.riskModel calculate];
[self performSelectorOnMainThread:@selector(showOutput) withObject:nil waitUntilDone:NO];
}
Thread 5 name: Dispatch queue: com.apple.root.default-priority
Thread 5 Crashed:
0 libobjc.A.dylib 0x3590cfd8 objc_msgSend + 44
1 RiskCalculator 0x000135dc -[RiskModel calculate] (RiskModel.m:193)
2 RiskCalculator 0x0000895e -[RiskModelViewController calculateRiskAutomaticallyWithOperation] (RiskModelViewController.m:82)
3 CoreFoundation 0x344fa80c __invoking___ + 60
4 CoreFoundation 0x344557da -[NSInvocation invoke] + 154
5 Foundation 0x32f4a698 -[NSInvocationOperation main] + 108
6 Foundation 0x32ee339c -[__NSOperationInternal start] + 856
7 Foundation 0x32f4c79c __block_global_6 + 96
8 libdispatch.dylib 0x334f1d4e _dispatch_call_block_and_release + 6
9 libdispatch.dylib 0x334f4890 _dispatch_worker_thread2 + 252
10 libsystem_c.dylib 0x330941c8 _pthread_wqthread + 288
11 libsystem_c.dylib 0x3309409c start_wqthread + 0`
Upvotes: 0
Views: 115