How Microsoft.Bcl.Async works?

后端 未结 2 1116
温柔的废话
温柔的废话 2021-02-08 04:37

Microsoft.Bcl.Async enables developers to use async/await keywords without .NET Framework 4.5 that they are supposed to target to use them.

Tha

相关标签:
2条回答
  • 2021-02-08 05:13

    async/await is nothing but C# 5.0 compiler transformation. There is no async/await at IL level.

    One simple example would be the using() { } statement which is also a compiler transformation. It just converts the using statement to try/finally block. However, there is a dependency on existence of IDisposable interface which is defined in .NET 1.1.

    Similarly, the async/await transformation depends on certain types like IAsyncStateMachine interface which are defined in .NET 4.5. The Microsoft.Bcl.Async gets those type definitions to .NET 4.0.

    EDIT

    How does the Microsoft.Bcl.Async assembly cause the compiler to recognize a new keyword (async/await)?

    No it does not. C# 5.0 compiler already knows about the keywords and what to do with them. However, it can't find the required types as project is targeted to .NET 4.0. The Microsoft.Bcl.Async package brings in those types.

    0 讨论(0)
  • 2021-02-08 05:25

    MS2012 is installing .net 4.5 so you cannot get 'compile errors with 4.0' as you described

    0 讨论(0)
提交回复
热议问题