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
.