NSThread 的产量?

发布于 2024-12-18 01:49:19 字数 316 浏览 2 评论 0原文

我有一个 NSOperationQueue,我想取消一些操作。因此我迭代操作并取消一些任务。在同一(UI)线程中随后执行的代码中的另一点,我检查队列中有多少操作。即使我取消所有操作,我也永远不会得到0。我猜这些操作需要正确处理取消。因此,我需要在取消后在我的 UI 线程中调用某种“yield”函数。有没有办法在 Cocoa Touch 中做到这一点?

我相当黑客的解决方案是取消后:

[NSThread sleepForTimeInterval:0.1];

知道如何让它变得更好吗?

谢谢, 拉尔斯

I have an NSOperationQueue and I want to cancel some operations. Therefore I iterate over the operation and cancel some tasks. At another point in the code which is executed subsequent in the same (UI) thread I check how many operations are in the queue. Even if I cancel all operations I get never 0. I guess the operations need to process the cancel properly. Therefore I would need some kind of "yield" function called in my UI thread after canceling. Is there a way to do that in Cocoa Touch?

My rather hackish solution is after cancel is:

[NSThread sleepForTimeInterval:0.1];

Any idea how to make that nicer?

Thanks,
Lars

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文