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.
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];
}
}
}
Yeah can also confirm it doesn't call cancel method on the operations, it just sets isCancelled = YES
My solution: [[[NSOperationQueue mainQueue] operations] makeObjectsPerformSelector:@selector(cancel)];
-cancelAllOperations
work just fine. Maybe you need to provide more context. – David Dunham Dec 21 '11 at 17:51mainQueue
forNSURLConnection
. You probably want to use a custom queue forNSURLConnection
-based operations, notmainQueue
, anyway (you can usemaxConcurrentOperationCount
to enjoy concurrency while controlling the degree of concurrency). If using delegate-basedNSURLConnection
, you can still schedule the connection on the main queue (or create your ownNSThread
with its own runloop, like AFNetworking does). But you probably want to use custom queue for the operations, themselves. – Rob Jul 15 '14 at 5:55