如何取消GCD队列?

时间:2015-01-27 22:28:14

标签: ios grand-central-dispatch

我需要知道尚未在串行GCD队列上启动的任务数。原因是我希望他们“取消”,就像这样:

if(!canceled) {
    ... do work
  }

1 个答案:

答案 0 :(得分:1)

感谢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()
    })