-1

enter image description here performSelector:onThread make the runloop exited? I try observer the runloop, when i touch, the runloop exited after finish handle performSelector:onThread , the timer stops working. i cant understand

Chen_
  • 59
  • 3
  • 1
    Please [don't post your code as an image](http://idownvotedbecau.se/imageofcode). Use the code formatting in markdown to embed your code into the question body itself. It's as simple as pasting it in, highlighting it and pressing the `{ }` button. – Mihai Chelaru Jun 13 '18 at 01:52

1 Answers1

1

From the documentation for -runMode:beforeDate::

Runs the loop once […]

(Emphasis added)

That is, this method does not "loop" the run loop. It just blocks once waiting for one single input source to fire. When such an input source does fire, the method returns.

Return Value

YES if the run loop ran and processed an input source or if the specified timeout value was reached […]

Again, the method returns when "the run loop ran and processed an input source or if the specified timeout value was reached" (emphasis added).

[This method] returns after either the first input source is processed or limitDate is reached.

-performSelector:onThread:... is implemented as a run-loop source, but that's an implementation detail. In general, unless you're running the run loop in a custom mode, you can't rely on only your app's input sources being scheduled on the run loop. Frameworks can schedule their own sources on it. So, you have to be prepared for that method to return.

So, you either have to loop around calls to -runMode:beforeDate: until some condition appropriate to your purposes occurs, or you need to use a custom mode both for the timer and when running the run loop. In the latter case, though, you need to schedule an input source of your own for that mode, because just the timer is not sufficient to make the run loop keep running.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154