call async method without await 2 using -'c#,,asynchronous,async-await,c#-5.0'

call async method without await 2  using -'c#,,asynchronous,async-await,c#-5.0'

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?


public bool ValidateRequest(string userName, string password)
    return ValidateRequestAsync(userName, password).Result;

I think this will cause a deadlock.


Calling the method like above makes the call never end. (The method doesn't reaches the end anymore)

asked Sep 7, 2015 by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.