Is it true that async should not be used for high-CPU tasks?

后端 未结 4 663
梦如初夏
梦如初夏 2021-01-31 04:11

I was wondering whether it\'s true that async-await should not be used for \"high-CPU\" tasks. I saw this claimed in a presentation.

So I guess

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 04:59

    Unless CalculateMillionthPrimeNumberAsync constantly uses async/await by itself, there is no reason not to let the Task to run heavy CPU work, since it just delegates your method onto ThreadPool's thread.

    What a ThreadPool thread is and how does it differ from a regular thread is written here.

    In short, it just takes the threadpool thread into custody for quite a time (and the number of threadpool threads is limited), so, unless you are taking too many them, there is nothing to worry about.

提交回复
热议问题