Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin BeginInvokeOnMainThread without Xamarin.Forms

Sorry for what I'm sure will turn out to be a very stupid question..

I am using Android UI not Xamarin Forms for the presentation layer in my Xamarin app, but I want to use the Activity.RunOnUIThread (from Android), which all Xamarin docs suggests is Device.BeginInvokeOnMainThread (from the Xamarin.Forms) project. Obviously I don't have this available since I don't have a reference on the xamarin.forms project.

Where do I find the run-on-ui-thread mechanism in Xamarin if I don't want to use Forms?

like image 378
Syntax Avatar asked Dec 02 '22 15:12

Syntax


1 Answers

Android:

Android Activitys have a RunOnUiThread method that you can use:

RunOnUiThread  ( () => {
    // manipulate UI controls
});

Ref: https://developer.xamarin.com/api/member/Android.App.Activity.RunOnUiThread/p/Java.Lang.IRunnable/

iOS:

InvokeOnMainThread (delegate {  
    // manipulate UI controls
});
like image 188
SushiHangover Avatar answered Jan 01 '23 16:01

SushiHangover