开发者

Reducing load on the main thread when using dispatch_get_main_queue()

I'm generating a lot of thumbnails in my iPhone app using GCD. I have something that look like this :

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // generate thumbnail

    // store thumbnail

    dispatch_async(dispatch_get_main_queue(), ^{
        // display thumbnail (cellForRowAtIndexPath and cell.imageView.image = ..
    });
);

It works pretty well, but I would 开发者_运维知识库like to lower the priority for the display block, in order to have a more responsive UI thread.


The main queue (associated with the main thread) doesn't have a priority. You can't change its priority.

Anyway, you may instead post a NSNotification using the NSPostWhenIdle posting style. This will allow your code to be executed only when your app have some idle time. See here in the documentation / dedicated Programming Guide about such techniques.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜