I have the following problem: I need to execute a function that is delayed after processing the HTTP request. A user can assign for a certain task, after 45 minutes I have to check if the task is done. If not, I have to reopen the task for others.
I have tried the following code:
[HttpPost]
[ActionName("addJob")]
public string AddJob([FromBody] Task task)
{
// Add task ...
RemoveTaskAfterTime(task);
return "Job has been added";
}
private async Task RemoveTaskAfterTime(Task task)
{
System.Diagnostics.Debug.WriteLine("started to wait");
await Task.Delay(5000);
System.Diagnostics.Debug.WriteLine("remove task");
}
For some reason, "started to wait" gets called but "remove task" not. It works with Thread.sleep, but in that case also the response takes 45 minutes, so that´s no solution. Would be awesome if somebody could help me! Thank you in advance