如何取消GCD队列?
How to cancel GCD queue?
我需要知道串行 GCD 队列上尚未启动的任务数。原因是我想让他们'cancel',像这样:
if(!canceled) {
... do work
}
感谢 Midhun MP 的改变真的很容易:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
// .. some code
//HERE I need cancel queue, but with GCD it is not possible
})
所以 NSOperationQueue
的解决方案:
var oq = NSOperationQueue()
oq.addOperationWithBlock({
// .. some code
oq.cancelAllOperations()
})
我需要知道串行 GCD 队列上尚未启动的任务数。原因是我想让他们'cancel',像这样:
if(!canceled) {
... do work
}
感谢 Midhun MP 的改变真的很容易:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
// .. some code
//HERE I need cancel queue, but with GCD it is not possible
})
所以 NSOperationQueue
的解决方案:
var oq = NSOperationQueue()
oq.addOperationWithBlock({
// .. some code
oq.cancelAllOperations()
})