await
or .Wait()
? This code should execute LongRunningTask()
on thread pool which will run it in another thread and it should not block your request thread.Task.Run
is ok, but if this endpoint is called too frequently or LongRunningTask
is too long, it may starve the thread pool, which will throttle your incoming requests. In those cases it is better to control the processing of long running tasks in a Background service using a queue.You may also use return Accepted(); //HTTP code 202
instead of Ok() //200
(which is also fine), as Accepted indicates asynchronous operation / background task.