main 方法。请参阅下面的示例。
main
-(void)main{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for( int i=0; i< 100; i++ ) { //Check for cancellation if( [self isCancelled] ){ [pool drain]; return; } //Do the work } [pool drain]; }
除了排水池之外,还有什么我应该做的,尽快退出这个方法吗?
1)优雅地退出
2) 适当通知听众/代表。如果有委托,则需要提供支持多个操作结果(成功、失败或错误、取消、超时)的回调或接口/协议。您的侦听器不一定是调用cancel的对象,但它们可能更好地了解如何处理这种情况。
isCancelled 如果操作在多线程上下文中操作。
isCancelled