iPhone:NSOperationQueue 串行运行操作

发布于 2024-08-30 16:59:42 字数 307 浏览 4 评论 0原文

我有一个单例 NSOperationQueue 来处理我的所有网络请求。然而,我注意到,当我运行一个特别长的操作时(该特定操作至少需要 25 秒),我的其他操作在其完成之前不会运行。

maxConcurrentOperationCount 设置为 NSOperationQueueDefaultMaxConcurrentOperationCount,所以我不认为这是问题所在。

有什么原因会发生这种情况吗?除了生成多个 NSOperationQueues(我不确定是否可行的解决方案,也不确定这是一个好主意)之外,解决此问题的最佳方法是什么?

谢谢。

I have a singleton NSOperationQueue that handles all of my network requests. I'm noticing, however, that when I have one particularly long operation running (this particular operation takes at least 25 seconds), my other operations don't run until it completes.

maxConcurrentOperationCount is set to NSOperationQueueDefaultMaxConcurrentOperationCount, so I don't believe that's the issue.

Any reason why this would be happening? Besides spawning multiple NSOperationQueues (a solution that I'm not sure would work, nor am I sure it's a good idea), what's the best way to fix this problem?

Thanks.

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

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

发布评论

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

评论(1

栩栩如生 2024-09-06 16:59:42

根据 NSOperationQueue 类参考NSOperationQueueDefaultMaxConcurrentOperationCount 的意思是“默认的最大操作数是由 NSOperationQueue 对象根据当前系统条件动态确定的”。我没有看到任何说明默认值将是 > 1(尤其是在单 CPU 系统上)。

尝试调用 -setMaxConcurrentOperationCount: 显式设置更大的值,看看是否有帮助。

According to the NSOperationQueue class referenceNSOperationQueueDefaultMaxConcurrentOperationCount means that "the default maximum number of operations is determined dynamically by the NSOperationQueue object based on current system conditions." I don't see anything that says the default will be > 1 (especially on a single-CPU system).

Try calling -setMaxConcurrentOperationCount: to explicitly set a larger value, and see if that helps.

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