I have an async method:
public async Task<bool> ValidateRequestAsync(string userName, string password)
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
string stringResponse = await response.Content.ReadAsStringAsync();
return bool.Parse(stringResponse);
}
}
I call this method like this:
bool isValid = await ValidateRequestAsync("user1", "pass1");
Can i call the same method from an synchronous method, without using await
keyword?
Ex:
public bool ValidateRequest(string userName, string password)
{
return ValidateRequestAsync(userName, password).Result;
}
I think this will cause a deadlock.
EDIT
Calling the method like above makes the call never end. (The method doesn't reaches the end anymore)
See Question&Answers more detail:os