如果 UIViewController 运行如下所示的后台线程操作并在完成之前被释放(假设它是从 UINavigationController 弹出的),后台线程是否停止?确保后台线程完成的好方法是什么?我担心的是,如果用户在字段中输入一个值,并且在解除分配视图控制器之前数据库没有更新,那么数据库将不会更新。
// Doing something on the main thread
dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);
dispatch_async(myQueue, ^{
// Perform long running process
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
});
});
// Continue doing other stuff on the
// main thread while process is running.