问题描述
在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:
您不能取消已排队的邮件使用这种方法.如果您想要取消消息的选项当前线程,您必须使用这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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!