performSelector NSThread问题 [英] performSelector NSThread issue

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

问题描述

在performSelector waitsUntilDone期间是否可以取消线程?

Is it possible to cancel a thread while performSelector waitsUntilDone?

参见下文:

我在以下行中有一个while循环:

I have a while loop with following line:

[self performSelector:@selector(getMyRecords:) onThread:myThread withObject:i waitUntilDone:YES]

有时,我需要在执行循环时取消线程 myThread .我遇到以下崩溃问题:

Sometimes, I need to cancel my thread myThread while my loop executes. I get following crash issue:

Terminating app due to uncaught exception 'NSDestinationInvalidException', reason: '*** -[MyController performSelector:onThread:withObject:waitUntilDone:modes:]: target thread exited while waiting for the perform'

推荐答案

查看NSObject的文档:

Check out the documentation of NSObject:

此方法将邮件排队在使用以下命令运行目标线程的循环默认的运行循环模式-即,与NSRunLoopCommonModes常数.作为一部分正常的运行循环处理目标线程使消息出队(假设它正在其中一个默认运行循环模式)并调用所需的方法.

This method queues the message on the run loop of the target thread using the default run loop modes—that is, the modes associated with the NSRunLoopCommonModes constant. As part of its normal run loop processing, the target thread dequeues the message (assuming it is running in one of the default run loop modes) and invokes the desired method.

您不能取消已排队的邮件使用这种方法.如果您想要取消消息的选项当前线程,您必须使用这performSelector:withObject:afterDelay:或者performSelector:withObject:afterDelay:inModes:方法.

You cannot cancel messages queued using this method. If you want the option of canceling a message on the current thread, you must use either the performSelector:withObject:afterDelay: or performSelector:withObject:afterDelay:inModes: method.

此方法保留接收者和arg参数,直到之后选择器已执行.

This method retains the receiver and the arg parameter until after the selector is performed.

这篇关于performSelector NSThread问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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