Cancel background thread in Objective-C

How to cancel background thread in Objective-C?

I call the background thread as follows:

[self performSelectorInBackground:@selector(setupThumbnails) withObject:nil];

It is called when a swipe occurs, for each scroll I want to cancel the previous background thread request.

+3
source share
1 answer

Keep the undo property for your stream and periodically check it in your stream. You need to either use a lock or an atomic function (as provided by the operating system and its frameworks, but not implemented by yourself!) To indicate that the stream should be canceled. System atomic functions are described in the man page atomic.

NSOperation NSOperationQueue NSThread. - , , NSOperation isCancelled, , NSOperation NSOperationQueue.

, " ", ​​ . , , , , . , .

+2

Source: https://habr.com/ru/post/1756391/


All Articles