Why Use Async/Await Over Normal Threading or Tasks?

后端 未结 5 1447
爱一瞬间的悲伤
爱一瞬间的悲伤 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:06

    Yes, it is a syntactic sugar that makes dealing with threads much easier, it also makes the code easier to maintain, because the thread management is done by run-time. await release the thread immediately and allows that thread or another one to pick up where it left off, even if done on the main thread.

    Like other abstractions, if you want complete control over the mechanisms under the covers, then you are still free to implement similar logic using thread signaling, etc.

    If you are interested in seeing what async/await produces then you can use Reflector or ILSpy to decompile the generated code.

    Read What does async & await generate? for a description of what C# 5.0 is doing on your behalf.

提交回复
热议问题