Why Use Async/Await Over Normal Threading or Tasks?

后端 未结 5 1452
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 04:15

I\'ve been reading a lot about async and await, and at first I didn\'t get it because I didn\'t properly understand threading or tasks. But after getting to grips with both

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 05:17

    If await was just calling Task.Wait we wouldn't need special syntax and new APIs for that. The major difference is that async/await releases the current thread completely while waiting for completion. During an async IO there is no thread involved at all. The IO is just a small data structure inside of the kernel.

    async/await uses callback-based waiting under the hood and makes all its nastiness (think of JavaScript callbacks...) go a way.

    Note, that async does not just move the work to a background thread (in general). It releases all threads involved.

提交回复
热议问题