NS调用操作问题
我的 Cocoa Mac 应用程序中有一个方法,可以遍历应用程序的 PubSub 客户端中的所有订阅源,并将所有条目标记为已读。
逻辑看起来像这样......
NSArray *feeds = [[PSClient applicationClient]feeds];
for(PSFeed *feed in feeds)
{
for(PSEntry *entry in [feed entries])
{
entry.read = NO;
}
}
如果有大量未读提要,则可能需要一段时间才能循环浏览所有提要(相对而言)。我希望用户能够做其他事情,例如滚动浏览文章,而其他事情在后台进行。因此,我有一个 NSInitationOperation 设置来调用该方法,就像这样...
NSInvocationOperation *opr = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(markAllReadOperation) object:nil];
[que addOperation:opr];
[opr release];
循环运行时应用程序仍然会经历严重的速度减慢。而且用户界面几乎没有响应。我是否遗漏了 NSInvocableOperation 的某些内容,或者我的逻辑本质上很慢?
I have a method in my Cocoa Mac application that goes through all subscribed feeds in my application's PubSub Client and marks all the entries as read.
The logic looks something like this...
NSArray *feeds = [[PSClient applicationClient]feeds];
for(PSFeed *feed in feeds)
{
for(PSEntry *entry in [feed entries])
{
entry.read = NO;
}
}
If there are a large number of unread feeds it can take a while to cycle through them all (relatively speaking). I would like the user to be able to do other things like scroll through articles while the other stuff is going on in the background. So I have an NSInvocationOperation setup to call the method, like so...
NSInvocationOperation *opr = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(markAllReadOperation) object:nil];
[que addOperation:opr];
[opr release];
The application still experiences severe slowdowns while the loop is running. And the UI is nearly unresponsive. Am I missing something with NSInvocationOperation, or is my logic just inherently slow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这听起来像是……中央调度局的工作!
当然,Grand Central Dispatch(和块)都是在 Mac OS X 10.6 中引入的,因此如果您需要支持旧版本的 OS X,则可能无法使用。
This sounds like a job for...Grand Central Dispatch!
Of course, Grand Central Dispatch (and blocks) were both introduced in Mac OS X 10.6, so that may not be usable if you need to support older versions of OS X.
如果您的 UI 无响应,则听起来好像主线程上正在运行某些内容。您没有使用
mainQueue
是吗?我认为最好的选择是使用 Instruments 来使用 Time Profiler 工具准确查看哪些代码导致速度减慢。
If your UI is unresponsive, then it sounds like something is running on the main thread. You're not using the
mainQueue
are you?I think your best bet would be to use Instruments to see exactly what code is causing the slowdown using the Time Profiler instrument.