How different is await/async from threading?

后端 未结 3 948
南方客
南方客 2020-12-15 04:51

I\'m trying to familiarize myself with c#\'s new await/async keywords, and I\'ve found several aspects which I can\'t quite understand.

  1. Let\'s start with ra

3条回答
  •  佛祖请我去吃肉
    2020-12-15 05:34

    In short, it seems like the answer is "very". While the following may not answer all your questions, I think it applies to a general enough use case. Think of your Stream instead of the network IO they're referring to.

    In the case of overlapped network IO, an IO completion port will be used, the callback being triggered by a hardware interupt.

    This means that while we "await" completion, a thread will not be consumed. [...]

    It is possible to do everything on 1 thread. [...] It will however depend on the platform, the "awaiter" implementation & the synchronization context being used.

    http://social.msdn.microsoft.com/Forums/en-US/async/thread/a46c8a54-f8d4-4fa9-8746-64d6a3a7540d/

提交回复
热议问题