开发者

Specify to call someting when main thread is idle

开发者 https://www.devze.com 2023-04-03 12:33 出处:网络
Say I have a low priority job. Like checking queues whether there are URL to grab, or stuff. How can I do that?

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

精彩评论

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