when should I use ConfigureAwait(true)

后端 未结 5 2054
灰色年华
灰色年华 2020-12-29 01:55

Has anyone come across a scenario for using ConfigureAwait(true)? Since true is the default option I cannot see when would you ever use it.

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 02:20

    true to attempt to marshal the continuation back to the original context captured; otherwise, false.

    It's actually more like saying that ConfigureAwait(true) is like using .ContinueWith( t => {...}, TaskScheduler.FromCurrentSynchronizationContext()), where ConfigureAwait(false) is like using .ContinueWith( t => {...}). If you pass false, then the continuation is being allowed to run on a thread-pool thread instead of pulling back to the current synchronization context.

提交回复
热议问题