I need to use the return of an asynchronous method for validation but even with the use of "await" the method is still running before I get the function return.
var teste = await new VendaService().EnviarVendaParaServicoCentral(new List<ItemVenda>(), new Venda());
if (teste)
{
MessageBox.Show("feito");
}
Asynchronous method with other asynchronous calls:
public async Task<bool> EnviarVendaParaServicoCentral(List<ItemVenda> itensVenda, Venda venda)
{
try
{
await this._conHelper._connection.Start();
this._vendaEfetuada = false;
await this._conHelper._hubProxy.Invoke("RealizarVenda", itensVenda, venda);
this._conHelper._hubProxy.On<bool>("RetornoDaVenda", (retornoServicoCentral) =>
this.Dispatcher.BeginInvoke(() =>
{
this._vendaEfetuada = retornoServicoCentral;
})
);
return this._vendaEfetuada;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}