Why is await async so slow?

前端 未结 4 1054
粉色の甜心
粉色の甜心 2020-12-14 18:27

I finally got VS2012 and got a simple demo up and working to check out the potential performance boost of async and await, but to my dismay it is slower! Its possible I\'m d

4条回答
  •  死守一世寂寞
    2020-12-14 19:26

    async isn't intended for heavy-duty parallel computation. You can do basic parallel work using Task.Run with Task.WhenAll, but any serious parallel work should be done using the task parallel library (e.g., Parallel). Asynchronous code on the client side is about responsiveness, not parallel processing.

    A common approach is to use Parallel for the parallel work, and then wrap it in a Task.Run and use await on it to keep the UI responsive.

提交回复
热议问题