How to kill / stop background thread?

So, I have a method that executes a loop and because of how my program works, I call this method using

[self performSelectorInBackground:@selector(myMethod:) withObject:arg];

And the method itself,

- (void)myMethod:(id)arg {
    //...

    for (//Loop Conditions) {
        if (stopMorse) {
            break;
        }
        //Do stuff
    }

    //...
}

Now I would like to allow the user to stop starting this loop, so there is a way to kill / stop the thread.

I tried adding BOOL, but the problem is that it does not seem to be updated because it is in a separate thread. What is the best way to stop this loop from starting?

+3
source share
1 answer

/ , , this .

, , , . , ?

+4

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


All Articles