ios - Does dispatch_after block the UI? -


i hoping learn whether there negative implications of running asynchronous nsurlconnection inside of dispatch. using dispatch because seems cleaner timer purposes.

the call asynchronous, want ensure using dispatch_after not block ui. can me understand if dispatch_after block ui/app in way 10 seconds? thank you!

int delayseconds = 10;  dispatch_after(dispatch_time(dispatch_time_now, (int64_t)(delayseconds  * nsec_per_sec)), dispatch_get_main_queue(), ^{      aurl = [nsurl urlwithstring:@"http://google.com"];     request = [nsmutableurlrequest requestwithurl:aurl                                       cachepolicy:nsurlrequestuseprotocolcachepolicy                                   timeoutinterval:60.0];      [nsurlconnection sendasynchronousrequest:request queue:     [nsoperationqueue mainqueue] completionhandler:^(nsurlresponse *response) {          //do response      }];  }); 

p.s. have taken @ does dispatch_after block main thread? i'm still bit confused.

the code inside dispatch_after doesn't block until runs after delay. runs on specified queue.

since specify main queue, code run on main ui thread. ui not "blocked" during delay.

but example bad one. while nsurl , nsurlrequest creation done on main thread, execution of request done asynchronously main thread not being blocked during request. not until completion handler called main thread again. because specific main queue completion block, not because dispatch_after being done on main thread.

so real code being run on main thread here nsurlconnection completion block. actual request done in background (since asynchronous). other code on main thread trivial.

and no thread being blocked during delayseconds before dispatched block run.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -