博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

NSOperationQueue

Posted on 2011-07-12 10:26  星尘的天空  阅读(326)  评论(0编辑  收藏  举报

Link Address http://www.cnblogs.com/chen1987lei/archive/2011/04/28/2032259.html

NSOperation

首先是建立NSOperationQueue和NSOperations。NSOperationQueue会建立一个线程,每个加入到线程operation会有序的执行。

NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc];
initWithTarget:self
selector:@selector(doWork:)
object:someObject];
[queue addObject:operation];
[operation release];

下面是使用NSOperationQueue的过程:

  1. 建立一个NSOperationQueue的对象
  2. 建立一个NSOperation的对象
  3. 将operation加入到NSOperationQueue中
  4. release掉operation

使用NSOperation有几种,现在介绍最简单的一种NSInvocationOperation,NSInvocationOperation是NSOperation的子类,允许运行在operation中的targer和selector

THE END !