79141415

Date: 2024-10-30 14:04:19
Score: 0.5
Natty:
Report link
  1. Is this the actual code that you are executing? Are you using any 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.
  2. 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.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Is this the
  • Low reputation (0.5):
Posted by: Mitko Petrov