如何使用GCD定期在后台运行代码块? [英] How can I run code block in background periodically using GCD?
问题描述
如何使用GCD定期在后台运行代码块?
我正在尝试用几个子系统编写一个游戏引擎,比如渲染,物理,游戏逻辑等等。有些任务应该是事件驱动的,但是有些任务(比如物理系统)应该在后台以恒定时间周期性地调用(例如在1/100秒之后)。
我创建了一个代码块,但是如何在后台定期运行此块?这里是GCD正确的工具吗?
How can I run code block in background periodically using GCD? I am trying to write a game engine with several subsystems, like rendering, physics, game logic and so on. Some tasks should be event-driven, but some (like physics system) should be called periodically in the background with constant time (for example after 1/100 sec). I created a block of code, but how can I run this block periodically in background? Is GCD right tool here?
推荐答案
你想要的是一个GCD调度源。有关示例代码,请参阅创建计时器示例。
What you want is a GCD dispatch source. For sample code, see the Creating a Timer Example.
这篇关于如何使用GCD定期在后台运行代码块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!