How can I call async method from constructor?

You can use a static method that returns an instance of your form

public class TestForm : Form
{
    private TestForm()
    {
    }

    public static async Task<TestForm> Create()
    {
        await myMethod();
        return new TestForm();
    }
}

Don't do this in the constructor but in the loaded event of the window instead. You can mark the loaded eventhandler as async.


My sample is to call student details from page constructor

1- the calling of navigation page

    void Handle_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e)
    {
        Student _student = (Student)e.Item;
        Navigation.PushAsync(new Student_Details(_student.ID));

    }

2 - the details page

public partial class Student_Details : ContentPage
{
    public Student_Details(int id)
    {
        InitializeComponent();
        Task.Run(async () => await getStudent(id));
    }

    public async Task<int> getStudent(int id)
    {
        Student _student;
        SQLiteDatabase db = new SQLiteDatabase();
        _student = await db.getStudent(id);
        return 0;
    }
}