Wait an async function in a fuction which isn't async with Xamarin.Forms

romainb78romainb78 FRMember


In Xamarin.Forms, I need to call an async function on overrided function OnBackButtonPressed() which isn't async.

Here is my code:

protected override bool OnBackButtonPressed()
    WSActivityIndicator.IsVisible = true;

    Device.BeginInvokeOnMainThread(async () =>
        await Utils.logOut(this);

    WSActivityIndicator.IsVisible = false;

    return true;

As you can see on the code above, the activity indicator don't stay visible until the end of Utils.logOut() function because the function is executed with Device.BeginInvokeOnMainThread().

How can I wait for the async function Utils.logOut() to finish before I hide the activity indicator and return true.


Sign In or Register to comment.