sandeep Gupta

sandeep Gupta

  • NA
  • 80
  • 816

how to make async method wait till it get result and then proceed ?

Jan 1 2021 7:37 AM
await generic.getFindocFunds(users);
 
 

public async Task getFindocFunds(Users users)
{
try
{
Uri requestUri = new Uri("https://fintrader.myfindoc.com/api/v1/funds/view?client_id=" + users.mst_User.UserId.ToString() + "&type=all");
var objClint2 = new System.Net.Http.HttpClient();
objClint2.DefaultRequestHeaders.Add("Authorization", "Bearer " + users.mst_User.Token);
objClint2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
System.Net.Http.HttpResponseMessage respon2 = await objClint2.GetAsync(requestUri);
string responJsonText2 = await respon2.Content.ReadAsStringAsync();
Dictionary<string, object> values1 = JsonConvert.DeserializeObject<Dictionary<string, object>>(responJsonText2);
if (values1["status"].ToString() == "success")
{
Dictionary<string, object> values21 = JsonConvert.DeserializeObject<Dictionary<string, object>>(values1["data"].ToString());
dynamic values22 = JsonConvert.DeserializeObject<dynamic>(values21["values"].ToString());
foreach (var item in values22)
{
if (item[0].ToString() == "Available")
{
users.cashAvailable = Convert.ToDouble(item[1]);
break;
}
}
}
}
catch (Exception ex)
{
Log.writeLog(ex, "getSamcoFunds()");
}
}
 
 
the main method does not wait for the called method result  and proceed with further execution
 
 
 

Answers (4)