Home > Blockchain >  how to call async method in MainPage
how to call async method in MainPage

Time:05-23

public partial class MainPage : ContentPage
{    
    public  MainPage()
    {
        InitializeComponent();
    }
}

I want to call here:

var status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();

How to do it?

CodePudding user response:

call it in OnAppearing

public override async void OnAppearing()
{
    var status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
}

CodePudding user response:

If you don't want to call this in the OnAppearing() method and specifically in the contructor, you can do this (watch out for possible thread blocking though):

public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            // watch out for possible thread blocking!
            Task.Run(async() =>
            {
                await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
            });
        }
    }
  • Related