在iphone应用程序中调度线程之后的线程 [英] scheduling a Thread after a Thread in iphone application

查看:110
本文介绍了在iphone应用程序中调度线程之后的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在线程完成后安排一个线程。

I want to schedule a thread after a thread completion.

有可能吗?如何?

例如(指定我的需要)

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    // 1. response - schedule myThread 
    // 2. response - schedule a new thread which will be executed after myThread
    // 3. response - schedule a new thread which will be executed after second thread
    // .....
}


推荐答案

如果您使用 NSOperations ,您可以使用 addDependency:方法来指定操作的依赖关系。

If you use NSOperations you can use the addDependency: method to specify an operation's dependencies.

NSInvocationOperation 可能对你有用,如果你去这条路线。

NSInvocationOperation will probably be useful to you if you go this route.

编辑:我只是重新阅读主题,你在iPhone上,所以你没有块,但作为参考,如果你有块可用, NSBlockOperation 更好。

I just re-read the subject and you're on iPhone so you don't have blocks, but for reference, if you have blocks available, NSBlockOperation is even better.

请注意,当使用这些方法来执行异步操作(并假设它们中的代码使用autorelease)时,您将负责实例化 NSAutoreleasePool 当您的方法开始运行并退出时释放/耗尽它。

Note that when using these methods to perform asynchronous operations (and assuming the code in them uses autorelease) you'll be responsible for instantiating an NSAutoreleasePool when your method starts running and releasing/draining it upon exit.

这篇关于在iphone应用程序中调度线程之后的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆