Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to a Block running on a GCD Dispatch Queue if app terminates?

What happens if a block is asynchronously executing on a background queue when the user quits the app? Will it be terminated? Is it down to me to handle in –applicationWillTerminate:?

I'm not talking about long running tasks.. just wondering if there is an inherent danger in doing anything that could lead to inconsistent state asynchronously?

like image 220
hooleyhoop Avatar asked Feb 06 '12 19:02

hooleyhoop


1 Answers

All threads (GCD created or not) are terminated when an app exits, so yes, the block will not be run (ever) if it hasn't already. If there's work being done that needs to complete before the app can safely exit then you can wait for that in -applicationWillTerminate, but it's really not a good idea to set things up that way since your app could also be force quit by the user and -applicationWillTerminate may never run.

like image 78
jkh Avatar answered Nov 07 '22 01:11

jkh