Personal I have an api where its processing takes around 6 hours of execution, so I added a Task.Factory.StartNew with the main processing. So when someone calls, it responds to StatusCode 200 and continues "heavy" processing with the Task:
public override async Task<HttpResponseMessage> Processar(TarefaViewModel tarefa){
var task = Task.Factory.StartNew(() =>
{
var result = ProcessamentoDe6HorasNoBanco();
// Chama HttpClient e responde para outra api externa:
RequestPostStatusGerenciador(result, tarefa.Id, Action.Processar);
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
return await ResponderAccepted("OK");
}
However, sometimes the Task is not called I have to recycle IIS to go back to normal. I suspect it is something related to IIS Cache. Can anyone give me a light on this issue? Would the Task.Factory.StartNew properties such as TaskCreationOptions.LongRunning make any difference?