How can I call this async method in my Xamarin Forms when my app starts?

As far as the docs say, you have the Application.OnStart event which you can override:

Application developers override this method to perform actions when the application starts.

You can execute your async method there where it can actually be awaited:

public override async void OnStart()
{
    await LoadStorageDataAsync();
}

Take a step back, and think about how the UI works. When your app is initially shown, the framework constructs your ViewModel and View, and then it shows something immediately (as soon as possible). That's an inappropriate place for network activity.

Instead, what you should do is start the asynchronous operation and then (synchronously) load and show a "loading" page. When the asynchronous operation completes, then you can transition to your other pages (or to an "error" page if, say, the user does not have network access).

I'm not sure if Xamarin Forms is capable of data-binding to a page object, but if it is, then my NotifyTaskCompletion type may be helpful.


Constructors can't be async, but event handlers can be. If you can you should move that logic to the OnStart event handler (or a more appropriate one):

public override async void OnStart (EventArgs e)
{
    // stuff
    await LoadStorageDataAsync();
    // stuff
}

If you can't, you don't have a better choice than simply blocking synchronously on that task to get the result. You should be aware though that this can lead to deadlocks.