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.
+1
A:
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.
NSOperationQueue documentation
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
}
Philippe Leybaert
2009-12-10 07:43:49
Thats amazing!!!
Nithin
2009-12-11 09:12:31
but when i implement this, a problem is occurring; if i give to laucnh this task, it works fine for the first time, but if i try to call it again while the first one running, the newer is executed and the other is just lost. What i came to know is to queue them, but don't know to implement it.
Nithin
2009-12-14 06:37:33
+1
A:
If you want to see an actual implementation of this, take a look at the source code for ASIHTTPRequest
.
Alex Reynolds
2009-12-10 08:01:52
For his application, it sounds like he should just use that wrapper and not worry about the underlying threading himself.
Brad Larson
2009-12-10 19:19:35