在 iOS 中暂停特定线程?

发布于 2024-10-31 02:32:41 字数 168 浏览 12 评论 0原文

在我的 iPhone 应用程序中,我使用了 2 个线程。两者在不同类别中的功能不同。在特定条件下,我想暂停特定线程,因此我使用了
[NSThread sleepForTimeInterval:]
所以我的问题是我做得对还是这个睡眠导致整个应用程序睡眠?如果是的话还有什么其他选择?

in my iPhone app, I have used 2 threads. Both functions differently in different class. On particular condition I want to pause particular thread so I have used
[NSThread sleepForTimeInterval:]
So my question is am I doing right or this sleep causes sleep in whole application? If yes what is other alternative?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

汐鸠 2024-11-07 02:32:41

如果您想将线程暂停给定的时间,那么 [NSThread sleepForTimeInterval:] 就可以了。但是,如果您想等待给定事件发生(例如等待另一个线程赶上),您应该查看 NSCondition 类。

If you want to pause your thread for a given amount of time, then [NSThread sleepForTimeInterval:] is just fine. However if you want to wait for a given event to occur (e.g. wait for another thread to catch up) you should take a look at the NSCondition class.

彩虹直至黑白 2024-11-07 02:32:41

是的,这是绝对正确的。这将暂停您正在调用的当前线程[NSThread sleepForTimeInterval:]

Yeah this is absolutely right. This will pause the current thread on which you are calling [NSThread sleepForTimeInterval:]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文