-
Can non-asynchronous calls be made to
WebApi
? -
I do not want my application to get hit by the method that runs the query with
WebApi
, I want it to wait for a response and take action according to the return, but all examples I saw of calls toWebApi
areAsync
. What should I do? -
Is my architecture wrong?
In this example I would like to load the grid
private void btnListaGenerica_Click(object sender, EventArgs e)
{
Task<List<Empresa>> ListEmpresa = this.GetAll<Empresa>();
dgvDados.DataSource = ListEmpresa;
}
private async Task<List<T>> GetAll<T>()
{
try
{
using (var client = new HttpClient())
{
using (var response = await client.GetAsync("http://localhost:49783/api/empresas/listall"))
if (response.IsSuccessStatusCode)
{
//clienteUri = response.Headers.Location;
var ProdutoJsonString = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T[]>(ProdutoJsonString).ToList();
}
else
{
return null;
}
}
}