작업 대기열에서 모든 작업을 취소해야합니다. 그러나 호출 cancelAllOperation 메서드 후에는 작업이 여전히 실행 중입니다. 간단한 예 : sleep
모닝콜하지 않습니다 작업을 취소취소 된 작업이 아직 실행 중입니다.
@interface MyOperation : NSOperation
@end
@implementation MyOperation
-(void)main {
NSLog(@"starting 1");
sleep(4);
NSLog(@"finished 1");
}
@end
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
MyOperation *op = [MyOperation new];
[queue addOperation:op];
sleep(2);
[queue cancelAllOperations];
NSLog(@"canceled");
}
log:
2014-07-23 09:55:48.839 MDict1[837:1303] starting 1
2014-07-23 09:55:50.842 MDict1[837:70b] canceled
2014-07-23 09:55:52.842 MDict1[837:1303] finished 1
그 전에 어떤 일을하기 전에 isCancelled 속성을 확인해야합니까? – congnd
작업을 시작하기 전에 작업을 취소하면 대부분 손상되지 않지만'main'은 호출되지 않습니다. – rmaddy
오케이, 이해합니다. 감사합니다. – congnd