开发者

Specify to call someting when main thread is idle

Say I have a low priority job. Like checking queues whether there are URL to grab, or stuff.

How can I do that?

I can use timer to check every seconds but I am sure the开发者_JAVA技巧re are better ways.


You can use GCD to schedule a task with low priority in the main queue.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
      //Your code here
});

You can put this code within a loop, timer or whatever you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜