Method 1: performSelectorOnMainThread [self performSelectorOnMainThread:@selector(updateUI:) withObject:image waitUntilDone:NO]; Dispatch_async (dispatch_get_main_queue(), ^{… })

  1. dispatch_async(dispatch_get_global_queue(0, 0), ^{  
  2. // A block of code that handles time-consuming operations…
  3.       
  4. // Tell the main thread to refresh
  5.     dispatch_async(dispatch_get_main_queue(), ^{  
  6. // To call the main thread to refresh,
  7.     });  
  8.       
  9. });  

Dispatch_async starts an asynchronous operation with the first parameter specifying a GCD queue and the second parameter assigning a block to the queue to process the transaction.

Dispatch_get_global_queue (0, 0) : global queue is used. \

Typically the system itself will have three queues. Global_queue, current_queue, and main_queue.

Getting a global queue takes two parameters, the first of which is the transaction handler block queue priority that I assign. The value can be high or low and default. 0 is the default, 2 is high, and -2 is low

[cpp]  view plain copy

  1. #define DISPATCH_QUEUE_PRIORITY_HIGH     2  
  2. #define DISPATCH_QUEUE_PRIORITY_DEFAULT  0  
  3. #define DISPATCH_QUEUE_PRIORITY_LOW     (-2)  

After processing something, you need to return the result to or refresh the UI main thread, and again, grab the main thread, block operation.

\