Specify to call someting when main thread is idle

前端 未结 1 804
难免孤独
难免孤独 2021-01-14 18:11

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

相关标签:
1条回答
  • 2021-01-14 18:48

    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 讨论(0)
提交回复
热议问题