I know that Task.Run will get a thread from threadpool to run that method, beside that why in the following code it needs to warp the task-returning method with Task.Run.
I am referring to the https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md
GOOD Task-returning methods are better since unhandled exceptions trigger the TaskScheduler.UnobservedTaskException.
public class MyController : Controller
{
[HttpPost("/start")]
public IActionResult Post()
{
*//this line, why wrap it in Task.Run
Task.Run(BackgroundOperationAsync);*
return Accepted();
}
public async Task BackgroundOperationAsync()
{
var result = await CallDependencyAsync();
DoSomething(result);
}
}