NSOperationQueue 多线程
staticNSOperationQueue * queue;
- (void)viewDidLoad
{
[superviewDidLoad];
queue = [[NSOperationQueuealloc] init];
NSInvocationOperation * op = [[NSInvocationOperationalloc] initWithTarget:selfselector:@selector(download) object:nil];
[queueaddOperation:op];
}
- (void)download {
NSURL * url = [NSURLURLWithString:@"http://www.youdao.com"];
NSError * error;
NSString * data = [NSStringstringWithContentsOfURL:url encoding:NSUTF8StringEncodingerror:&error];
if (data != nil) {
[selfperformSelectorOnMainThread:@selector(download_completed:) withObject:data waitUntilDone:NO];
} else {
NSLog(@"error when download:%@", error);
queue = nil;
}
}
- (void) download_completed:(NSString *) data {
NSLog(@"call back");
self->contentLabel.text = data;
queue = nil;
}
NSOperationQueue 多线程的更多相关文章
- 多线程下NSOperation、NSBlockOperation、NSInvocationOperation、NSOperationQueue的使用
本篇文章主要介绍下多线程下NSOperation.NSBlockOperation.NSInvocationOperation.NSOperationQueue的使用,列举几个简单的例子. 默认情况下 ...
- IOS 多线程02-pthread 、 NSThread 、GCD 、NSOperationQueue、NSRunLoop
注:本人是翻译过来,并且加上本人的一点见解. 要点: 1.前言 2.pthread 3.NSThread 4.Grand Central Dispatch(GCD) 5.Operation Queue ...
- iOS多线程-03-NSOperation与NSOperationQueue
简介 通过NSOperation与NSOperationQueue的组合也能实现多线程 通常将任务封装成NSOperation对象,并将对象添加到NSOperationQueue中实现 NSOpera ...
- IOS多线程(NSOperation,NSOperationQueue)
含义:NSOperation,NSOperationQueue是什么. The NSOperation class is an abstract class you use to encapsulat ...
- 用NSOperation和NSOperationQueue实现多线程编程
1.上一讲简单介绍了NSThread的使用,虽然也可以实现多线程编程,但是需要我们去管理线程的生命周期,还要考虑线程同步.加锁问题,造成一些性能上的开销.我们也可以配合使用NSOperation和NS ...
- 多线程下的NSOperation和NSOperationQueue的使用
多线程下的NSOperation和NSOperationQueue的使用 NSOperation和NSOperationQueue的介绍: NSOperation是Cocoa中的一个抽象类,用来封装单 ...
- [转] iOS多线程编程之NSOperation和NSOperationQueue的使用
<iOS多线程编程之NSThread的使用> 介绍三种多线程编程和NSThread的使用,这篇介绍NSOperation的使用. 使用 NSOperation的方式有两种, 一种是用定义好 ...
- Swift - 多线程实现方式(2) - NSOperation和NSOperationQueue
1,Swift继续使用Object-C原有的一套线程,包括三种多线程编程技术: (1)NSThread (2)Cocoa NSOperation(NSOperation和NSOperationQueu ...
- [ios2]使用NSOperationQueue简化多线程开发和队列的优先级 【转】
多线程开发是一件需要特别精心的事情,即使是对有多年开发经验的工程师来说. 为了能让初级开发工程师也能使用多线程,同时还要简化复杂性.各种编程工具提供了各自的办法.对于iOS来说,建议在尽可能的情况下避 ...
随机推荐
- winform学习之----打开文件对话框并将文件内容放入文本框
OpenFileDialog ofg = new OpenFileDialog(); ofg.Title = "ddd";//设置对话框标题 ofg.Multiselect = t ...
- UIWebView弹出键盘按钮显示中文
UIWebView是一个很常用的视图,一般用来加载网页,比如百度: 点击文本框输入框后,会弹出一个带有toolbar的键盘,toolbar中有3个辅助按钮 有了这3个按钮,是方便很多,但默认是英文的, ...
- Grasshopper 2.0 MP Color FireWire 1394b (Sony ICX274)
相机参数如下,参见这里: Resolution 1624 x 1224 Frame Rate 30 FPS Megapixels 2.0 MP Chroma Color Sensor Name ...
- select @@identity的用法
用select @@identity得到上一次插入记录时自动产生的ID 如果你使用存储过程的话,将非常简单,代码如下:SET @NewID=@@IDENTITY 说明: 在 一条 INSERT.SEL ...
- C#并行库(TaskParallelLibrary)用法小结
今天有空,总结一下.NET 4.5并行库(TaskParallelLibrary)用法. 也许C和C++的程序员刚刚开始写C#还习惯于new Thread来新建一个线程,但新建线程需要内存和CPU上下 ...
- #在FLAT模式下,需要设置flat子网,VM的IP从这个设置的子网中抓取,这时flat_injected需要设置为True,系统才能自动获得IP,如果flat
#在FLAT模式下,需要设置flat子网,VM的IP从这个设置的子网中抓取,这时flat_injected需要设置为True,系统才能自动获得IP,如果flat子网和主机网络是同一网络,网络管理员要注 ...
- 【新产品发布】EVC9001 USB 隔离器
一. 简介 EVC9001采用Analog Device 公司的基于芯片级变压器的iCoupler 磁耦合隔离方案,完成了对USB接口双向隔离功能,隔离电压达 2500V(隔离电源模块 3000V隔 ...
- 2016.07.08,英语,《Vocabulary Builder》Unit 24
mand/mend comes from mandare, Latin for 'entrust' or 'order'. command and commandment: [kə'mændmənt] ...
- mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干
1.mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干 2.一般来说,事务是必须满足4个条件(ACID): Atomicity(原子性).Con ...
- PHP 计算出内存最高占用.
PHP 计算出内存最高占用. 代码可以计算出内存是否完全被使用, ini设置处:memory_limit = 1024M 代码跑完将显示如下信息: memory_limit:320M all ...