I want to know how to call my function
on the main thread.
How do I make sure my function
is called on the main thread?
(this follows a previous question of mine).
If you're on a background thread and want to execute code on the main thread, you need to call async() again. This time, however, you do it on DispatchQueue. main , which is the main thread, rather than one of the global quality of service queues.
It has been in the loop of constantly processing events and hibernation to ensure that user events can be responded as soon as possible. The reason why the screen can be refreshed is because `Main Runloop` is driving. Assume we use our Magical UIKit, and update UI on background threads.
The main thread is the one that starts our program, and it's also the one where all our UI work must happen. However, there is also a main queue, and although sometimes we use the terms “main thread” and “main queue” interchangeably, they aren't quite the same thing.
This will do it:
[[NSOperationQueue mainQueue] addOperationWithBlock:^ { //Your code goes in here NSLog(@"Main Thread Code"); }];
Hope this helps!
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