How do a library provide async methods if it is a bad practice to do Task.Run?

UberFace

In this article: https://blog.stephencleary.com/2013/11/taskrun-etiquette-examples-dont-use.html , it is advised against using Task.Run. however there are lot of libraries that provide methods that ends with Async and hence I expect those methods to return a running task that I can await (which however is not necessary, since those libraries could decide to return a synchronous task).

The context is a ASP.NET application. How am I supposed to make a method running in parallel?

What I understand is that async calls are executed in parallel if they contain at least one "await" operator inside, the problem is that the innermost call, should be parallel to achieve that, and to do that I have somewhat to resort to Task.Run

I have also seen some examples using TaskCompletionSource, is this necessary to implement the "inner most async method" to run a method in parallel in a ASP.NET application?

Damien_The_Unbeliever

In an ASP.Net application we tend to value requests/s over individual response times1 - certainly if we're directly trading off one versus the other. So we don't try to focus more CPU power at satisfying one request.

And really, focussing more CPU power at a task is what Task.Run is for - it's for when you have a distinct chunk of work to be done, you can't do it on the current thread (because its got its own work to do) and when you're free to use as much CPU as possible.

In ASP.Net, where async shines is when we're dealing with I/O. Nasty slow things like accessing the file system or talking to a database across the network. And wonderfully, at the lowest level, the windows I/O system is async already and we don't have to devote a thread just to waiting for things to finish.

So, you won't be using Task.Run. Instead you'll be looking for I/O related objects that expose Async methods. And those methods themselves will not, as above, be using Task.Run. What this does allow us to do is to stop using any threads for servicing our particular request whilst there's no work to be done, and so improve out requests/s metric.


1This is a generalization but single user/request ASP.Net sites are rare in my experience.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Do you have to put Task.Run in a method to make it async?

From Dev

How do I get a custom Rake task to run in Sinatra?

From Dev

Where do async methods run?

From Dev

How do I provide access to the library I wrap with cgo?

From Dev

Async methods that do not need cancellation

From Dev

How do I spawn a task that will run to completion and immediately return to the client?

From Dev

Run a Task, do something and then wait?

From Dev

How do i force java methods to run specific implementations

From Dev

How do i return a result from a async task

From Dev

How do static methods run?

From Dev

How do I Update Run Result on Task Completion?

From Dev

How to do async task in non-concurrent custom nsoperation

From Dev

How do I schedule a task to run once?

From Dev

How do I declare a generic async Task?

From Dev

Is using Task.Run a bad practice?

From Dev

How do I define the callback in the Async library's "Each" function?

From Dev

Async Task Best Practice

From Dev

How to get string from async task and do in background

From Dev

How do I hold the Async Task from executing before the user input is stored in a variable that is required by the Async Task

From Dev

How do I provide arguments to a command run from gksudo?

From Dev

How do I spawn a task that will run to completion and immediately return to the client?

From Dev

How do you know what methods to use for a task?

From Dev

Ruby on Rails: How do I run an automated rake task on Heroku

From Dev

submitting registration crashes at do in background of async task

From Dev

How do static methods run?

From Dev

How do I run a Supervisor task from cron.hourly?

From Dev

How do I run methods on respond_with json data in Rails?

From Dev

How do I set a task to run at specific time

From Dev

Is it a bad practice to do search using post request?

Related Related

  1. 1

    Do you have to put Task.Run in a method to make it async?

  2. 2

    How do I get a custom Rake task to run in Sinatra?

  3. 3

    Where do async methods run?

  4. 4

    How do I provide access to the library I wrap with cgo?

  5. 5

    Async methods that do not need cancellation

  6. 6

    How do I spawn a task that will run to completion and immediately return to the client?

  7. 7

    Run a Task, do something and then wait?

  8. 8

    How do i force java methods to run specific implementations

  9. 9

    How do i return a result from a async task

  10. 10

    How do static methods run?

  11. 11

    How do I Update Run Result on Task Completion?

  12. 12

    How to do async task in non-concurrent custom nsoperation

  13. 13

    How do I schedule a task to run once?

  14. 14

    How do I declare a generic async Task?

  15. 15

    Is using Task.Run a bad practice?

  16. 16

    How do I define the callback in the Async library's "Each" function?

  17. 17

    Async Task Best Practice

  18. 18

    How to get string from async task and do in background

  19. 19

    How do I hold the Async Task from executing before the user input is stored in a variable that is required by the Async Task

  20. 20

    How do I provide arguments to a command run from gksudo?

  21. 21

    How do I spawn a task that will run to completion and immediately return to the client?

  22. 22

    How do you know what methods to use for a task?

  23. 23

    Ruby on Rails: How do I run an automated rake task on Heroku

  24. 24

    submitting registration crashes at do in background of async task

  25. 25

    How do static methods run?

  26. 26

    How do I run a Supervisor task from cron.hourly?

  27. 27

    How do I run methods on respond_with json data in Rails?

  28. 28

    How do I set a task to run at specific time

  29. 29

    Is it a bad practice to do search using post request?

HotTag

Archive