Re: [問題] 請問Cocoa程式要如何一直做同件事情?
再補充一下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
討論串 (同標題文章)
完整討論串 (本文為第 7 之 7 篇):