I see that all you need to do is fire an event and forget, so the async/await is not the best option, after all the await will wait for the return.
You can achieve the expected result as follows.:
public class Program
{
public void Main()
{
// Realiza algum processo;
this.Cadastrar();
// Realiza algum processo;
}
public void Cadastrar()
{
// Realiza algum processo;
Task.Run(() => this.PessoaNotificacao(pessoa.Nome));
// Realiza algum processo;
}
public void PessoaNotificacao(string nome)
{
// realiza algum processo longo.
}
}
In the example above the Cadastrar will continue execution in parallel to PessoaNotificacao.
In any case there is no guarantee that the PessoaNotificacao will successfully finish the execution, so the best thing to do is to use the HangFire to manage the execution of the same.:
public class Program
{
public void Main()
{
// Realiza algum processo;
this.Cadastrar();
// Realiza algum processo;
}
public void Cadastrar()
{
// Realiza algum processo;
BackgroundJob.Enqueue(() => Program.PessoaNotificacao(pessoa.Nome));
// Realiza algum processo;
}
[DisplayName("Notificação enviada para {0}")]
public static void PessoaNotificacao(string nome)
{
// realiza algum processo longo.
}
}
Related: http://answall.com/questions/7760/operacoes-async-em-asp-net?rq=1
– Marllon Nasser
There’s that links for questions on the subject at http://answall.com/a/175305/101. It is probably a duplicate of one of them. Or the question is unclear.
– Maniero