-1

I started to read docs and blogs about the .net async programming model. In all documents it says use async if the operation is a blocking work(access file system, access network, access sql etc. any remote data storage (if you have more examples for blocking works please share them)).

What if my system has enough power to run all works without using async model. Do I need still need async?

I know that you will say don't waste the thread who is calling the blocking work, but think that I have lots of free threads on threadpool.

Please threat my question from an asp.net application perspective

Yucel
  • 2,603
  • 5
  • 28
  • 40
  • It is not about "having power". Things run at different speed, so code will have to wait frequently. Async allows you to do something while waiting is some situations. – Brian Rasmussen Feb 05 '16 at 17:54
  • When I say "having power", I mean having more core and thus means more ThreadPool can handle more simultaneous thread – Yucel Feb 05 '16 at 17:56
  • And that's the point. This is not about doing more work in parallel. It's about waiting/utilizing the wait. You hard disk isn't going to be any faster regardless of how many cores you have. If you read from disk, you can either wait for the operation to complete or do something while you wait. – Brian Rasmussen Feb 05 '16 at 19:39

2 Answers2

0

The purpose of using async for all non-CPU-bound work is that it delegates the decision-making for resource allocation out of your app entirely, and smarter layers can make decisions about how to optimally distribute work across cores, when to share threads or not, etc.

Rex M
  • 142,167
  • 33
  • 283
  • 313
0

Async (by async I assume you mean the TAP) code is not parallelization, so this is not the same of using threads from the thread pool to offload other work. Async simply makes more efficient use of the thread; rather than blocking a thread while you wait for the disk or network to do some work, you free that thread up to do something else while it waits for the disk or network to finish. If your program is pretty linear, and has no other work to do while it's waiting for those resources, then no async code is pretty pointless.

CodingGorilla
  • 19,612
  • 4
  • 45
  • 65