Home > Mobile >  Is it ok to use Task.Run() in ASP.NET to provide parallelism?
Is it ok to use Task.Run() in ASP.NET to provide parallelism?

Time:09-29

I read Is Task.Run considered bad practice in an ASP .NET MVC Web Application? which recommends against using Task.Run().

However, what if you had 3 different intensive CPU bound methods you wanted to run in parallel.

Couldn't you use await Task.WhenAll(task1, task2, task3)?

Wouldn't this result in a response being sent to the client sooner, at the expense of having fewer threads in the thread pool available to pick up new HTTP requests?

CodePudding user response:

Wouldn't this result in a response being sent to the client sooner, at the expense of having fewer threads in the thread pool available to pick up new HTTP requests?

Yes. But you're probably underestimating the impact it would have on your scalability. If you want to do this, be sure to do load testing with and without parallelism before putting this into production.

I can say from experience that every single time I've done this, I've had to roll it back later.

  • Related