RazorMAn
RazorMAn

Reputation: 11

Xamarin.Forms how to call async Task in App OnStart()

I try to do some chechking everytime when user try to start the application. This is my code example:

      protected override async void OnStart()
        {


            // Handle when your app starts
            var user = await FinDataStore.GetUserToken(DependencyService.Get<ISharedFunctions>().GetUser().UserName,   DependencyService.Get<ISharedFunctions>().GetUserPassword());
            if (user != null && user.AccessToken != null)
            {
                DependencyService.Get<ISharedFunctions>().SaveAccessToken(user.AccessToken);
                DependencyService.Get<ISharedFunctions>().SaveUser(user);
                DependencyService.Get<ISharedFunctions>().SaveRefreshToken(user.RefreshToken);
                DependencyService.Get<ISharedFunctions>().SaveUserFirmi(user.Firmi);
            }
            else
            {
                ((App)Application.Current).Logout();
            }
        }

but i get the error:

Error   CS0120  An object reference is required for the non-static field, method, or property 'FinDataStore.GetUserToken(string, string)'   

This is the call :

  public async Task<User> GetUserToken(string username, string password)

How to solve this?

Upvotes: 0

Views: 369

Answers (1)

Alessandro Caliaro
Alessandro Caliaro

Reputation: 5768

It's seems not to be a async problem. It seems you should do something like:

var myclass = new FinDataStore();

then you can

var ret = await myClass.GetUserToken...

Upvotes: 1

Related Questions