How does C# 5.0's async-await feature differ from the TPL?

后端 未结 7 1631
孤城傲影
孤城傲影 2020-12-07 10:48

I don\'t see the different between C#\'s (and VB\'s) new async features, and .NET 4.0\'s Task Parallel Library. Take, for example, Eric Lippert\'s code from here:

         


        
7条回答
  •  囚心锁ツ
    2020-12-07 10:55

    Anders boiled it down to a very succinct answer in the Channel 9 Live interview he did. I highly recommend it

    The new Async and await keywords allow you to orchestrate concurrency in your applications. They don't actually introduce any concurrency in to your application.

    TPL and more specifically Task is one way you can use to actually perform operations concurrently. The new async and await keyword allow you to compose these concurrent operations in a "synchronous" or "linear" fashion.

    So you can still write a linear flow of control in your programs while the actual computing may or may not happen concurrently. When computation does happen concurrently, await and async allow you to compose these operations.

提交回复
热议问题