问题描述
有人能指出解释穿线的花絮吗?在我的应用程序中,我正在将一些数据(甚至是大尺寸的图像)上传到Servlet.通常,取决于带宽,上载过程可能会花费相当长的时间.因此,我需要在其中实现线程,以便上传过程在后台进行.这里的任何专家都可以发布示例或教程链接或类似内容.预先感谢.
Can anyone point out a turorial which explains threading?? In my application, i'm uploading some data (even large sized images) to the servelet. The uploading process may take quite a large time depending on the bandwidth, as usual. So i need to implement threading in it so that the uploading process takes place in the background. Any experts here, may please post an example or a tutorial link or something like that.Thanks in advance.
推荐答案
启动后台任务的一种非常简单而强大的方法是使用 NSOperation 和 NSOperationQueue .它允许您创建一个类(继承自NSOperation),该类表示可以放置在后台处理的线程队列中的任务.
A very simple and robust way of launching background tasks is using NSOperation and NSOperationQueue. It allows you to create a class (inherited from NSOperation) that represents a task which can be placed in a threaded queue which is handled in the background.
另一种在后台启动内容的简便方法是使用 performSelectorInBackground 方法:
Another easy way of launching something in the background is by using the performSelectorInBackground method:
- (void) launchTask {
[self performSelectorInBackground:@selector(backgroundTask) withObject:nil];
}
- (void) backgroundTask {
// stuff to do in background
}
这篇关于使用来自iPhone的线程进行HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!