如何在NSOperationQueue中暂停NSOperation? [英] How can I Pause a NSOperation in a NSOperationQueue?

查看:570
本文介绍了如何在NSOperationQueue中暂停NSOperation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要暂停一个运行的NSOperation插入一个NSOperationQueue。目前我取消所有操作并重新启动它们。但这将导致在所完成的过程中出现某种重复。我尝试使用NSOperationQueue的setSuspended标志。但它不会暂停操作。有什么办法吗?

I need to pause a running NSOperation which was inserted in an NSOperationQueue. Currently I am canceling all operations and restarting them. But this would lead to some kind of duplication in terms of process done. I tried with setSuspended flag of NSOperationQueue. But it's not suspending the operation. Is there any way out?

推荐答案

请参阅:链接

此处来自苹果文档


暂停和恢复队列
如果您要发出临时停止执行操作,可以使用setSuspended:方法暂停相应的操作队列。

Suspending and Resuming Queues If you want to issue a temporary halt to the execution of operations, you can suspend the corresponding operation queue using the setSuspended: method.

暂停队列不会导致已执行的操作在任务中暂停。它只是阻止新操作被调度执行。您可以暂停一个队列以响应用户请求,暂停任何正在进行的工作,因为期望用户最终可能希望恢复该工作。

Suspending a queue does not cause already executing operations to pause in the middle of their tasks. It simply prevents new operations from being scheduled for execution. You might suspend a queue in response to a user request to pause any ongoing work, because the expectation is that the user might eventually want to resume that work.

这篇关于如何在NSOperationQueue中暂停NSOperation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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