关于在iphone操作系统中使用NSOperationQueue和NSOperation的问题

发布于 2024-09-30 17:29:15 字数 233 浏览 0 评论 0原文

我使用 NSOperation 执行任务:使用 NSURLConnection 下载一些文件,然后合并消耗大量 cpu 和内存的文件
我需要在新/后台线程中执行任务
因此,我将一些任务添加到 NSOperationQueue 并设置 maxConcurrentOperationCount = 2
但结果是合并文件时会阻塞主线程(UI有一段时间没有响应) ,它似乎没有在新的/后台线程中执行
如何让它按照我的预期进行?

Im using NSOperation to do a task: download some files with NSURLConnection and then merge files that spend much cpu and memory
I need to excute the task in new/background thread
So I add some these tasks to NSOperationQueue and set maxConcurrentOperationCount = 2
But the result is when merging files it will block the main thread(UI not respond for a while)
,it seems not excuting in new/background thread
how to make it go as I expected ?

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

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

发布评论

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

评论(2

风尘浪孓 2024-10-07 17:29:15

您要在 NSOperationQueue 中放入什么类型的操作? Apple 的 NSOperationQueue 文档包含以下注释:

注意:在 iOS 中,操作队列不
使用Grand Central Dispatch来执行
运营。他们创建单独的
非并发操作的线程
并从中启动并发操作
当前线程。供讨论
并发之间的区别
和非并发操作以及如何
它们被执行,请参阅 NSOperation 类参考。

What type of operations are you putting in the NSOperationQueue? Apple's documentation for the NSOperationQueue includes this note:

Note: In iOS, operation queues do not
use Grand Central Dispatch to execute
operations. They create separate
threads for non-concurrent operations
and launch concurrent operations from
the current thread. For a discussion
of the difference between concurrent
and non-concurrent operations and how
they are executed, see NSOperation Class Reference.

情魔剑神 2024-10-07 17:29:15

由于您使用 NSOperationqueue,因此您一次只有两个文件,并且只能合并它们,因为所有其他线程或文件都不存在。

因此,为了将它们合并在一起,您必须同时将它们保持在一起。

Since you using NSOperationqueue,therefore you are having only two files at one time and you can merge only them because all the other threads or files are not present there.

So for merging them together you will have to keep them together at one time.

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