Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们的要求之一可以通过每 30 分钟运行一次 NSTimer 或后台线程/作业来实现,它每分钟轮询特定的应用程序“状态”。
但我想知道与 NSTimer 相比,这个后台作业的 CPU 密集程度如何,如果差别不大,那么我们将使用后台线程/作业。
谢谢
线程非常轻量级。
事实上,您可以很好地在主线程上进行 NSTimer 轮询,然后使用 GCD 使用内联块在私有串行队列(在另一个线程上)上执行实际工作。这样,您的代码在不牺牲任何性能的情况下仍然非常可读。
请注意,NSTimer 不保证精确的计时精度,但我认为这并不重要。