I have seen this code snippet:
dispatch_async(dispatch_get_main_queue(), ^{ [self doSomeNetworkStuff]; });
This doesn't look like making much sense to me.
EDIT: To clarify the conditions of my question:
dispatch_async
is performed from the main thread.doSomeNetworkStuff
is the heavy lifting worker task.Dispatch, sure, but using the main queue would just pull the dispatched task back to the ui thread and block it.
Please, am I missing something? Thanks.
Submits a block for asynchronous execution on a dispatch queue and returns immediately.
Submits a block object for execution and returns after that block finishes executing.
A dispatch object that prioritizes the execution of tasks based on their quality-of-service (QoS) level.
Returns a system-defined global concurrent queue with the specified quality-of-service class.
dispatch_async
lets your app run tasks on many queues, so you can increase performance. But everything that interacts with the UI must be run on the main thread. You can run other tasks that don't relate to the UI outside the main thread to increase performance.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //Add some method process in global queue - normal for data processing dispatch_async(dispatch_get_main_queue(), ^(){ //Add method, task you want perform on mainQueue //Control UIView, IBOutlet all here }); //Add some method process in global queue - normal for data processing });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With