Re: How to update UI from a background thread
Re: How to update UI from a background thread
- Subject: Re: How to update UI from a background thread
- From: Quincey Morris <email@hidden>
- Date: Wed, 21 Sep 2016 10:00:48 -0700
- Feedback-id: 167118m:167118agrif8a:167118sBxmbFOggm:SMTPCORP
On Sep 21, 2016, at 09:20 , Dave <email@hidden> wrote:
>
> The time consuming method I am calling is in a third party library and it must be called in the main thread.
You cannot update UI on a background thread, so if the library method is blocking the main thread you’re out of luck. The only solution is to get the library author to write proper code.
If the library method is running on the main thread and calling back to a block of your code (which sounds like the case), then it’s safe execute code that issues UI updates, but you likely won’t see the results until later, after your app returns to the main event loop.
If a time-consuming operation *is* running on a background thread, it can dispatch_async a block to the main thread to update the UI, but then you must consider thread safety, if the update is referencing data that’s still being modified as the background thread continues to run.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden