Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Simon Tillson for Background thread NSRunloop run does not exit after NSTimer is invalidated! Why?

This stops a run loop fine for me:

[[NSRunLoop currentRunLoop] runUntilDate: [NSDate date]];

If you're writing code which may be run on the main thread (and hence uses the main runloop) though, you should check to see if your current runloop is the main runloop before doing this - otherwise you'll bomb your app.

// Kill the runloop now.NSRunLoop* rl = [NSRunLoop currentRunLoop]; // Get the runloopif (rl != [NSRunLoop mainRunLoop]){    // Set it running again, but only until now.     // In other words, STOP!!!    [rl runUntilDate: [NSDate date]];}

Viewing all articles
Browse latest Browse all 4

Trending Articles