WaitUntilDOne在performSelectorOnMainThread中有什么意义? [英] What is the significance of WaitUntilDOne in performSelectorOnMainThread?

查看:123
本文介绍了WaitUntilDOne在performSelectorOnMainThread中有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

performSelectorOnMainThread WaitUntilDOne 的重要性是什么?

以什么方式将 YES NO 设置为 WaitUntilDone 可以在应用程序上?

IN what way the YES or NO set to WaitUntilDone can have on the App?

更新:

我的问题应该是:在什么情况下他们有什么区别?

My Question should have been: In what scenarios do they make difference?

Sergio的回答是我期待的那个。

Sergio's answer was the one I was expecting.

推荐答案

来自 Apple文档关于 waitUntilDone


一个布尔值,指定当前线程是否阻塞,直到在主线程上的接收器上执行指定的选择器之后。指定YES以阻止此线程;否则,指定NO以使此方法立即返回。
如果当前线程也是主线程,并且您为此参数指定了YES,则会立即传递和处理消息。

A Boolean that specifies whether the current thread blocks until after the specified selector is performed on the receiver on the main thread. Specify YES to block this thread; otherwise, specify NO to have this method return immediately. If the current thread is also the main thread, and you specify YES for this parameter, the message is delivered and processed immediately.

您必须关注正在执行的线程 performSelectorOnMainThread 。该线程将阻塞并等待主线程完成该选择器;例如,工作者线程需要向主线程发送消息(例如,将一些信息存储到不是线程安全的某个中央存储器)。在发出同类操作之前,worker可能希望阻塞并等待操作完成。所以, waitUntilDone 在这种情况下会派上用场。

You have to focus on which thread is executing performSelectorOnMainThread. That thread will block and wait until the main thread has completed that selector; say, e.g., that a worker thread needs sending a message to the main thread (e.g., to store some info to some central store which is not thread-safe). The worker might want to block and wait for the operation to complete before issuing another operation of the same kind. So, waitUntilDone come in handy in such case.

这篇关于WaitUntilDOne在performSelectorOnMainThread中有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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