DotNETWeekly-io / DotNetWeekly

DotNet weekly newsletter
MIT License
201 stars 3 forks source link

【文章推荐】异步高级功能 #611

Closed gaufung closed 2 months ago

gaufung commented 2 months ago

https://www.youtube.com/watch?v=GQYd6MWKiLI&list=WL&index=1&ab_channel=NDCConferences

gaufung commented 2 months ago

image

异步 await 是 C# 中特色,这个演讲中,作者分享了异步中的高级用法

  1. 使用 await 而不是 Wait() 或者 Result
  2. 使用 Fire and Forget 方式处理无结果任务
  3. 避免 return await 方法
  4. 使用 ConfigureAwait(false)
  5. 使用 ConfigureAwait(ConfigureAwaitOptions options) 方法
  6. 使用 ValueTask
  7. 对于流数据,使用 IAsyncEnumerable 8.使用 waitAsync(CancellationToken)
  8. 使用 IAsyncDisposable