How and when to use ‘async’ and ‘await’

前端 未结 21 1801
你的背包
你的背包 2020-11-21 05:07

From my understanding one of the main things that async and await do is to make code easy to write and read - but is using them equal to spawning background threads to perfo

21条回答
  •  清酒与你
    2020-11-21 05:39

    is using them equal to spawning background threads to perform long duration logic?

    This article MDSN:Asynchronous Programming with async and await (C#) explains it explicitly:

    The async and await keywords don't cause additional threads to be created. Async methods don't require multithreading because an async method doesn't run on its own thread. The method runs on the current synchronization context and uses time on the thread only when the method is active.

提交回复
热议问题