Nâng CaoC# iconC#

SynchronizationContext là gì và tại sao nó quan trọng?

SynchronizationContext đảm bảo async continuations resume trên đúng thread.

  • Trong UI frameworks (WPF, WinForms), UI operations phải chạy trên UI thread — SynchronizationContext xử lý điều này tự động.
  • Classic ASP.NET (System.Web) cũng dùng per-request SynchronizationContext — nhưng ASP.NET Core thì KHÔNG: Core cố tình loại bỏ nó (Kestrel không install SynchronizationContext). ConfigureAwait(false) bỏ qua context này, hữu ích trong library code nơi thread cụ thể không quan trọng.

Xem toàn bộ C# cùng filter theo level & chủ đề con.

Mở danh sách C#