The apps should receive httpresponsemessage from LoginUser() but it becomes not responding.
private void button1_Click(object sender, EventArgs e)
{
if (LoginUser(tUser.Text, Password.Text).Result.IsSuccessStatusCode)
{
Notifier.Notify("Successfully logged in.. Please wait!");
}
else
{
Notifier.Notify("Please check your Credential..");
}
}
public async Task<HttpResponseMessage> LoginUser(string userid, string password)
{
string URI = "http://api.danubeco.com/api/userapps/authenticate";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("c291cmF2OmtheWFs");
using (var response = await client.GetAsync(String.Format("{0}/{1}/{2}", URI, userid, password)))
{
return response;
}
}
}
Please help!
You are blocking the UI thread and causing a deadlock. From Stephen Cleary's blog (Just replace
GetJsonAsync
with yourLoginUser
method, andGetStringAsync
withclient.GetAsync
):And the simple available solutions (also from the blog):
The 2nd solution suggests that you change
button1_Click
into: