我的项目是一个基于计算的标准,我们填充首先通过网络服务提取的coredata
的必填字段列表。
可以选择计算和重置字段。由于计算花费了大量时间并冻结了应用,因此我使用NSInvocationOperation
将其添加到NSOperationQueue
。
每当我输入“calculate”操作正在排队并且没有时间重置它时,应用程序崩溃并且控制台显示它已经在[RiskModel calculate]崩溃,这正在调用排队操作。
有没有更好的解决方案来执行此功能
- (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`