Fork me on GitHub

文章分类 -  MutiThread

上一页 1 2

使用NSOperationQueue简化多线程开发
摘要:多线程开发是一件需要特别精心的事情,即使是对有多年开发经验的工程师来说。为了能让初级开发工程师也能使用多线程,同时还要简化复杂性。各种编程工具提供了各自的办法。对于iOS来说,建议在尽可能的情况下避免直接操作线程,使用比如NSOperationQueue这样的机制。可以把NSOperationQueue看作一个线程池,可往线程池中添加操作(NSOperation)到队列中。线程池中的线程可看作消费者,从队列中取走操作,并执行它。你可以设置线程池中只有一个线程,这样,各个操作就可以认为是近似的顺序执行了。为什么说是近似呢,后面会做解释。编写最简单的示例先写个最简单的示例。编写一个NSOperat 阅读全文

posted @ 2012-02-09 14:42 pengyingh 阅读(3907) 评论(0) 推荐(0) 编辑

iphone 实行http post 及多线程编程实例
摘要:#import "FirstUIAppDelegate.h" @implementation FirstUIAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch //[self postdata]; [self setupThread]; [window makeKeyAndVisible]; } -(voi 阅读全文

posted @ 2012-02-09 11:05 pengyingh 阅读(260) 评论(0) 推荐(0) 编辑

使用NSOperation和NSOperationQueue启动多线程
摘要:在app store中的很多应用程序非常的笨重,他们有好的界面,但操作性很差,比如说当程序从网上或本地载入数据的时候,界面被冻结了,用户只能等程序完全载入数据之后才能进行操作。当打开一个应用程序时,iphone会产生一个包含main方法的线程,所用程序中的界面都是运行在这个线程之中的(table views, tab bars, alerts…),有时候我们会用数据填充这些view,现在问题是如何有效的载入数据,并且用户还能自如的操作程序。方法是启动新的线程,专门用于数据的下载,而主线程不会因为下载数据被阻塞。不管使用任何编程语言,在实现多线程时都是一件很麻烦的事情。更糟糕的是,一旦出错,这种 阅读全文

posted @ 2012-02-08 17:00 pengyingh 阅读(173) 评论(0) 推荐(0) 编辑

ios多线程学习笔记(2)
摘要:Operation Objects:Anoperation objectis an instance of theNSOperationclass (in the Foundation framework) that you use to encapsulate work you want your application to perform. TheNSOperationclass itself is an abstract base class that must be subclassed in order to do any useful work. Despite being ab 阅读全文

posted @ 2012-02-06 00:50 pengyingh 阅读(795) 评论(0) 推荐(0) 编辑

ios多线程学习笔记(1)
摘要:Threads introduce a tremendous amount of overhead to your process, both in terms of memory consumption and CPU time. 除非有必要,尽量不要使用Threads.Run Loop:A run loop is a piece of infrastructure used to manage events arriving asynchronously on a thread. A run loop works by monitoring one or more event source 阅读全文

posted @ 2012-02-06 00:49 pengyingh 阅读(513) 评论(0) 推荐(0) 编辑

上一页 1 2

导航