CFRunLoop学习

from CFRunLoop Reference

CFRunLoop monitors sources of input to a task and dispatches control when they become ready for processing.

Examples of input source might include user input devices,network connection,periodic or timed-delay events,and asynchronous callbacks.

Three types of objects can be monitored by a run loop:

sources(CFRunLoopSource)

timers(CFRunLoopTimer)

observers(CFRunLoopObserver)

Each sources,times or observers added to a run loop must be associated with one or more run loop modes.

There is exactly one run loop per thread.

RunLoop 是事件循环,用于schedule work 和协调输入事件.

RunLoop 接受2种不同的事件源,input sources (异步事件)和 timer sources(同步事件)

何时使用RunLoop?

1.使用ports或自定义输入源 与其他线程通讯

2.在线程中使用定时器

3.在程序中使用performSelector等方法

4.让线程周期性执行某个任务

posted @ 2012-03-12 12:28  Kalou  阅读(1056)  评论(0编辑  收藏  举报