A run loop requires at least one "input source" to run. The main run loop does, but you have to add a source manually to get a secondary run loop's -run
method to do anything. There's some documentation on this here.
One na?ve way to get this to work would be just to put [[NSRunLoop currentRunLoop] run]
in an infinite loop; when there's something to do, it'll do it, and return immediately otherwise. The problem is that the thread will take a decent amount of processor time simply waiting for something to occur.
Another solution is to install an NSTimer on this run loop to keep it alive.
But, if possible, you should use a mechanism designed for this sort of thing. If possible, you may want to use NSOperationQueue
for background operations.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…