作者atst (电脑无法阻止人类做蠢事)
看板MacDev
标题Re: [问题] 请问Cocoa程式要如何一直做同件事情?
时间Mon May 12 20:38:01 2008
再补充一下NSRunLoop的使用时机:
1. Use ports or custom input sources to communicate with other threads.
2. Use timers on the thread.
3. Use any of the performSelector… methods in a Cocoa application.
4. Keep the thread around to perform periodic tasks.
摘自
http://0rz.tw/8745v (Threading Programming Guide)
基本上的原则就是,当你的Thread要做的工作,
有必要与别的thread做比较复杂的互动时,(例如,要在某个thread中动态增加工作)
就可以考虑使用NSRunLoop.
其他的情况,还是简单一点,使用NSTimer与NSThread就好了。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.84.252.229