指定在主线程空闲时调用someting [英] Specify to call someting when main thread is idle

查看:60
本文介绍了指定在主线程空闲时调用someting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我的工作优先级低.就像检查队列中是否有要抓取的URL或东西一样.

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

我该怎么做?

我可以使用计时器每秒钟检查一次,但是我确信有更好的方法.

I can use timer to check every seconds but I am sure there are better ways.

推荐答案

您可以使用GCD在主队列中安排低优先级的任务.

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.

这篇关于指定在主线程空闲时调用someting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆