Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cancelAllOperations doesn't work for [NSOperationQueue mainQueue]

cancelAllOperations() doesn't work on the mainQueue (the cancel() method is not called on the NSOperation object). Am I missing something? I have to iterate through all operations and call the cancel() method to get it work.

like image 466
Alexander Avatar asked Dec 21 '11 13:12

Alexander


1 Answers

I can also confirm that cancelAllOperations does not work on [NSOperationQueue mainQueue] (at least on my iOS 5.0 Simulator). Might be intentionally designed like that since it is a shared instance.

My simple workaround is just to subclass NSOperation or NSBlockOperation without overriding anything and then do something like this:

-(void)cancelMyOperationsInMainQueue {    
    for (NSOperation* o in [[NSOperationQueue mainQueue] operations]) {
        if ([o isKindOfClass:[MyOperation class]]) {
            [o cancel];
        }
    }
 }
like image 94
Rollin_s Avatar answered Sep 19 '22 18:09

Rollin_s