Organizational Research By

Surprising Reserch Topic

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


call async method without await 2  using -'c#,asp.net,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?

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)
    
asked Sep 7, 2015 by rajesh
0 votes
22 views



Related Hot Questions



Government Jobs Opening


...