davidfowl / AspNetCoreDiagnosticScenarios

This repository has examples of broken patterns in ASP.NET Core applications
7.64k stars 735 forks source link

ASP.NET Core does have a SynchronizationContext when using Blazor #99

Open Sebazzz opened 1 year ago

Sebazzz commented 1 year ago

Avoid using Task.Result and Task.Wait:

https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/0c82fa823796c38d0436c0c08665c944ab12f91d/AsyncGuidance.md?plain=1#L232

ASP.NET Core Blazor does appear to use a synchronization context, being the RendererSynchronizationContext](https://source.dot.net/#Microsoft.AspNetCore.Components/Rendering/RendererSynchronizationContext.cs,11).

davidfowl commented 1 year ago

It does! Specifically, in Blazor Server when executing razor components (I should probably change that now).

Sebazzz commented 1 year ago

Yup, I should have specifically mentioned Blazor Server. This SynchronizationContext implementation doesn't necessarily schedule the work on the same thread like the WPF, WinForms and legacy ASP.NET does. It is prone to the same blocking issues however, I think.