Async all the way down?

前端 未结 2 2038
星月不相逢
星月不相逢 2020-12-16 13:29

Trying to understand the new async/await pattern, I have one question which I can\'t find an answer to, namely if I should decorate my methods with async, if I intend to cal

2条回答
  •  时光说笑
    2020-12-16 14:32

    The async in the signature is there to allow the compiler to create the state-machine rewriting of the contained code that is necessary to implement the await semantics in the general case.

    Your example is exactly the special case where you do not need that rewriting: The asynchronous operation is the last thing happening within a method. That kind of method is already possible and valid in .NET4.0. This compatibility might be one reason to avoid async when you do not need it.

提交回复
热议问题