6.14 Creating Dependency Between Operations
来源:互联网 发布:网络社会工程学是什么 编辑:程序博客网 时间:2024/06/05 20:40
在某个任务完成后才开始另一个任务
没什么好说的,上例子
- (void) firstOperationEntry:(id)paramObject{
NSLog(@"First Operation - Parameter Object = %@", paramObject);
NSLog(@"First Operation - Main Thread = %@", [NSThreadmainThread]);
NSLog(@"First Operation - Current Thread = %@", [NSThreadcurrentThread]);
}
- (void) secondOperationEntry:(id)paramObject{
NSLog(@"Second Operation - Parameter Object = %@", paramObject);
NSLog(@"Second Operation - Main Thread = %@", [NSThreadmainThread]);
NSLog(@"Second Operation - Current Thread = %@", [NSThreadcurrentThread]);
}
-(void)test6_14
{
NSNumber *firstNumber = [NSNumbernumberWithInteger:111];
NSNumber *secondNumber = [NSNumbernumberWithInteger:222];
NSInvocationOperation *firstOperation;
NSInvocationOperation *secondOperation;
NSOperationQueue *operationQueue;
firstOperation = [[NSInvocationOperationalloc] initWithTarget:self
selector:@selector(firstOperationEntry:)object:firstNumber];
secondOperation = [[NSInvocationOperationalloc] initWithTarget:self
selector:@selector(secondOperationEntry:)object:secondNumber];
[firstOperationaddDependency:secondOperation];
// [firstOperation removeDependency:secondOperation];
operationQueue = [[NSOperationQueuealloc] init];
/* Add the operations to the queue */
[operationQueueaddOperation:firstOperation];
[operationQueueaddOperation:secondOperation];
NSLog(@"Main thread is here");
}
输出:
2014-03-12 10:27:22.158 cookbook[505:a0b] Main thread is here
2014-03-12 10:27:22.158 cookbook[505:1403] Second Operation - Parameter Object = 222
2014-03-12 10:27:22.159 cookbook[505:1403] Second Operation - Main Thread = <NSThread: 0x8950130>{name = (null), num = 1}
2014-03-12 10:27:22.159 cookbook[505:1403] Second Operation - Current Thread = <NSThread: 0x8c917d0>{name = (null), num = 2}
2014-03-12 10:27:22.160 cookbook[505:1403] First Operation - Parameter Object = 111
2014-03-12 10:27:22.160 cookbook[505:1403] First Operation - Main Thread = <NSThread: 0x8950130>{name = (null), num = 1}
2014-03-12 10:27:22.161 cookbook[505:1403] First Operation - Current Thread = <NSThread: 0x8c917d0>{name = (null), num = 2}
显然firstOperation是在secondOperation执行完成后才开始执行的。这是通过[firstOperationaddDependency:secondOperation];这句实现的。
如果想取消这种依赖关系,则用 [firstOperationremoveDependency:secondOperation];
- 6.14 Creating Dependency Between Operations
- Circular dependency between the following tasks:
- Item7 Distinguish between () and {} when creating objects
- Too many content provider operations between yield points解决方法
- Operations
- CRUD Operations Using the Generic Repository Pattern and Dependency Injection in MVC
- CRUD Operations Using the Generic Repository Pattern and Dependency Injection in MVC
- Dependency
- Error creating bean with name 'menuController': Injection of autowired dependency……
- #159 – Creating a Read-Only Dependency Property(创建一个只读的依赖属性)
- Error creating bean with name 'menuController' Injection of autowired dependency…
- Error creating bean with name 'hotWordServiceImpl': Unsatisfied dependency expressed through field '
- How to capture the one-to-one dependency between two attributes in one relation?
- ERROR: failed to establish dependency between database sgerp5 and diskgroup resource ora.DATA.dg
- There is a circular dependency between XMPPFramework/Core and XMPPFramework/Authentication
- Odoo ORM API (二)- Creating Models、Compatibility between new API and old API
- Between
- Error creating bean with name 'userService' defined in class path resource [beans.xml]: Unsatisfied dependency expressed through
- 合并时间段 Merge Intervals
- 基于HTTP协议的轻量级开源简单队列服务
- Android应用如何适配不同分辨率的手机
- 使用Spring MVC3构建Web应用详细教程
- bootrom的构成
- 6.14 Creating Dependency Between Operations
- Exception Handling in Asp.net MVC
- 读undo问题
- github如何删除一个repository(仓库)
- js 与 php 通过json数据进行通讯
- 总结一下新人工作初期的容易犯的错
- [iOS] 如何将你的程序打包成ipa
- Hdu 2571 命运(简单DP)
- 算法 第一周课外作业