從背景執行緒操作 UI
後臺執行緒無法修改 UI; 幾乎所有 UIKit 方法都必須在主執行緒上呼叫。
從 NSObject 的子類(包括任何 UIViewController 或 UIView):
InvokeOnMainThread(() =>
{
// Call UI methods here
});
從標準的 C#類:
UIApplication.SharedApplication.InvokeOnMainThread(() =>
{
// Call UI methods here
});
InvokeOnMainThread 等待在主執行緒上執行的程式碼在繼續之前執行。如果你不需要等待,請使用 BeginInvokeOnMainThread。