Quote:
Originally Posted by RLScott
If you force an end to a thread, then there would be no opportunity for that thread to clean up its resource allocations.
|
Right, as mentioned in the documentation
Quote:
Originally Posted by RLScott
So instead of trying to force an end to the thread, look for ways to change the thread so that it periodically checks for a notification from the main UI thread that it should stop. Then the worker thread can gracefully stop what it is doing and exit.
|
Hmm yes, but I will have to count the number of actives threads I think.
I currently have a view controller which launches this loading image background thread.
In another view controller (parent of the above view controller), users can click a button which will have for effect to load new images in the child view controller.
If the user clicks fast on the button, for instance 3 times, what I observe is :
- the image which corresponds to the first time the user clicked is displayed
- the second image is then displayed once loaded
- the third image is then displayed once loaded
In the above case, I need to stop loading the images of the 2 first clicks to only display the third. Should I count the number of active threads and display image only if the last thread ?
something like :
- (void) displayProductsImages: (Product *) theProduct
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
nbThreads = countTheNbOfActiveThreadsInThisViewController();
if(nbThreads == 1)
{
// code that download images using dataWithContentsOfURL function
.....
// code that displays the loaded image
....
}
[pool release];
}
If the above seems correct, I need to be able to count the numbers of active threads, is there a way to do that ?
Thanks again for your time, really appreciate ...
J