I have a static class with a async method in it . The async method awaits a user action (user needs to confirms on a dialog). I need to call this method in a constructor in App.xaml.cs (xamarin)
public static class StoragePermission
{
public static async Task Check()
{
try
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
if (status != PermissionStatus.Granted)
{
var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });
status = results[Permission.Storage];
}
}
catch (Exception ex) {}
}
}
And I have tried calling this method in the constructor like this:
StoragePermission.Check().Wait();
But doing the above , I dont get the next code to invoke at all. After the user action, focus does not return to the code.
I have also tried it this way:
public Task StorageInitialization { get; private set; }
and then within constructor, I do
StorageInitialization = StoragePermission.Check();
But doing this code returns to the next line in constructor, but does not wait for the user action to be completed.
I appreciate if someone could help me with this