Xamarin.iOS Concurrent Programming in Xamarin.iOS Manipulating UI from background threads

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Background threads cannot modify the UI; almost all UIKit methods must be called on the main thread.

From a subclass of NSObject (including any UIViewController or UIView):

InvokeOnMainThread(() =>
{
    // Call UI methods here
});

From a standard C# class:

UIApplication.SharedApplication.InvokeOnMainThread(() =>
{
    // Call UI methods here
});

InvokeOnMainThread waits for your code running on the main thread to execute before continuing. If you don't need to wait, use BeginInvokeOnMainThread.



Got any Xamarin.iOS Question?