Does .NET resume an await continuation on a new different thread pool thread or reuse the thread from a previous resumption?

后端 未结 4 1054
礼貌的吻别
礼貌的吻别 2021-01-20 23:30

Does .NET resume an await continuation on a new different thread pool thread or reuse the thread from a previous resumption?

Let\'s image below C# code in a .NET Core co

4条回答
  •  不知归路
    2021-01-21 00:17

    There is no real async call in your sample code ie. An i/o call so most likely the continuation is inlined on the original thread as an optimization. In your async methods if you add await Task.Delay you may observe continuation may run on a different thread. Bottomline never make any assumptions on which thread the continuations run, assume it gets run on another thread.

提交回复
热议问题