Các blocking call như .Result dừng thread hiện tại lại để chờ task hoàn thành.
- Trong UI app (WPF, WinForms) hoặc classic ASP.NET (có SynchronizationContext), nếu continuation của task cần dùng đúng thread đó thì cả hai cùng chờ nhau — deadlock kinh điển.
- Lưu ý: ASP.NET Core (Kestrel) KHÔNG cài SynchronizationContext nên deadlock này không xảy ra ở đó — nhưng vẫn nên tránh
.Resultvì block thread pool. - Luôn dùng
awaitthay thế.
Blocking calls like .Result halt the current thread waiting for task completion.
- In UI apps (WPF, WinForms) or classic ASP.NET (which installs a per-request SynchronizationContext), if the task's continuation needs that same thread, both end up waiting — a classic deadlock.
- Note: ASP.NET Core (Kestrel) does NOT install a SynchronizationContext, so this deadlock does not apply there — but
.Resultshould still be avoided as it blocks thread pool threads. - Always use
awaitinstead.