0

我的项目是一个基于计算的标准,我们从coredata首先通过 web 服务获取的必填字段列表中填充。

有一个计算和重置字段的选项。由于计算需要很长时间并冻结应用程序,我使用NSInvocationOperation将其添加到NSOperationQueue.

每当我输入“计算”时,一个操作正在排队,如果没有时间重置它,应用程序崩溃并且控制台显示它已经在 [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`
4

0 回答 0