I am developing application in which my thread is starting when connectionDidFinishLoading.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[downloadingthread cancel];
downloadingthread = [[NSThread alloc]initWithTarget:self selector:@selector(startusingthread) object:nil];
[downloadingthread start];
}
connectionDidFinishLoading is called multiple times, so I want to stop download thread and then start agin it again. I am trying to execute last thread only. Please help me to stop my thread in between.
Never stop a thread by force.
You stop the request using
-[NSURLConnection cancel].Your thread should be on a run loop, so you would cancel the run loop for that thread if you are aborting the request but… it’s very expensive to create threads all over the place, and there is often a better alternative to this problem.