DiogoMartins
DiogoMartins

Reputation: 87

Task<bool> error in Xamarin.Forms make program stop

i recently started working with Xamarin and my level of noob its very high right now, i will resume my problem.

I am developing an app that can reach a WebService to send and import data from DB, right now i am currently working on a login page and i have a method so I can check if the user exits in the data base, when i added the service reference in Xamarin all the methods turned into async, and because of that i need to use tasks.

So, i implemented the Tasks and it worked perfectly but i had one problem i couldn´t send the response of the server back, i did some research and found that tasks methods dont have returns and for that i could use Task < TResult>, and i implemented in this way:

CheckUser Method in Service

serclient = new Service.WebService1SoapClient()


public async Task<bool> CheckUser(string UserName)
{
    var resp = await serClient.CheckUserAsync(UserName); 
    bool result = resp.Body.CheckUserResult;
    return result;
}

gesTab.CheckUser Is the method to check the database.

public bool CheckUser(string username)
        {
             bool e = gestTab.CheckUser(username);

            return e;
        }

When the program is runnig just stops in the first line of that function and i cant understand why.

I already tried it by using pointers by keeping getting that pointers must only be used in unsafe context.

If i cant do it this way, what can i do for return the data?

Thank you all.

Upvotes: -1

Views: 351

Answers (1)

Batuhan
Batuhan

Reputation: 1611

You must await the method which retrieves data from db or etc. like this ,

public async Task<bool> CheckUser(string username)
{
  bool e = await gestTab.CheckUser(username);
  return e;
}

Since your method making starting async request but not awaiting response, your application crashes unexpectedly.

Upvotes: 0

Related Questions