如何停止在调度队列中执行任务? [英] How to stop the execution of tasks in a dispatch queue?

查看:330
本文介绍了如何停止在调度队列中执行任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个串行队列,我怎么能从主线程告诉它立即停止执行并取消它的所有任务?

If I have a serial queue, how can I, from the main thread, tell it to immediately stop execution and cancel all of its tasks?

推荐答案

这是一个非常常见的问题,我之前已经回答过:

This is a pretty common question, and one I've answered before:

暂停GCD查询问题

简短的回答是GCD没有取消API;你必须自己实施你的取消代码。在上面的答案中,我基本上展示了如何做到这一点。

The short answer is that GCD doesn't have a cancellation API; you have to implement your cancellation code yourself. In my answer, above, I show basically how that can be done.

这篇关于如何停止在调度队列中执行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆