Method 1: performSelectorOnMainThread [self performSelectorOnMainThread:@selector(updateUI:) withObject:image waitUntilDone:NO]; Dispatch_async (dispatch_get_main_queue(), ^{… })
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- // A block of code that handles time-consuming operations…
- // Tell the main thread to refresh
- dispatch_async(dispatch_get_main_queue(), ^{
- // To call the main thread to refresh,
- });
- });
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
- #define DISPATCH_QUEUE_PRIORITY_HIGH 2
- #define DISPATCH_QUEUE_PRIORITY_DEFAULT 0
- #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.
\