如何停止NSInvocationOperation? [英] How to stop an NSInvocationOperation?

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

问题描述

我有一个NSInvocationOperation,它将在后台下载并解析一系列NSXMLDocuments到我的UI响应中.

I have an NSInvocationOperation that would download and parse a series of NSXMLDocuments in the background to my UI responsive.

我试图停止Invocation操作的方法是调用NSOperationQueue的cancellAllOperations.但这似乎不会停止调用的执行.

My attempt at stopping the Invocation operation is to call my NSOperationQueue's cancellAllOperations. But it seems that this won't stop the invocation's execution.

关于如何解决此问题的任何想法?

Any ideas on how would I go about this problem?

推荐答案

NSOperation对象的实现取决于实际停止的工作,清理并在获取时退出通知它已被取消.您要取消队列中所有操作的消息将导致队列停止使正在运行的新操作出队,并将取消消息发送到当前正在运行的任何操作.

It's up to the implementation of your NSOperation object to actually stop what it's doing, clean up, and exit when it gets notified that it's been cancelled. Messaging that you want to cancel all operations on the queue will cause the queue to stop dequeueing new operations to run and will send the cancel message to any operations currently running.

在操作的主要方法中,您应该检查isCancelled并在实际取消操作时处理该状态.

In your operation's main method, you should be checking for isCancelled and handling that state when you are actually cancelled.

有关更多信息,请参见创建和管理操作对象.

For more information, see the Creating and Managing Operation Objects in the Threading Programming Guide.

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

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