Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 2.22 KB

main-thread-updates-ui.md

File metadata and controls

40 lines (31 loc) · 2.22 KB
title description ms.service ms.assetid ms.subservice author ms.author ms.date no-loc
Main Thread Control Updates on iOS
Platform-specifics allow you to consume functionality that's only available on a specific platform, without implementing custom renderers or effects. This article explains how to consume the iOS platform-specific that enables control layout and rendering updates to be performed on the main thread.
xamarin
945E711D-9BD2-4BF9-9FB3-CBE0D5B25A49
xamarin-forms
davidbritch
dabritch
10/24/2018
Xamarin.Forms
Xamarin.Essentials

Main Thread Control Updates on iOS

This iOS platform-specific enables control layout and rendering updates to be performed on the main thread, instead of being performed on a background thread. It should be rarely needed, but in some cases may prevent crashes. Its consumed in XAML by setting the Application.HandleControlUpdatesOnMainThread bindable property to true:

<Application ...
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
             ios:Application.HandleControlUpdatesOnMainThread="true">
    ...
</Application>

Alternatively, it can be consumed from C# using the fluent API:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
...

Xamarin.Forms.Application.Current.On<iOS>().SetHandleControlUpdatesOnMainThread(true);

The Application.On<iOS> method specifies that this platform-specific will only run on iOS. The Application.SetHandleControlUpdatesOnMainThread method, in the Xamarin.Forms.PlatformConfiguration.iOSSpecific namespace, is used to control whether control layout and rendering updates are performed on the main thread, instead of being performed on a background thread. In addition, the Application.GetHandleControlUpdatesOnMainThread method can be used to return whether control layout and rendering updates are being performed on the main thread.

Related links