When is it necessary to manually call StateHasChanged(), and what are the performance implications of calling it too frequently?
Last updated
Call
StateHasChangedmanually for changes outside Blazor's triggers: timers, background threads, external callbacks, or intermediate progress in long async work (viaInvokeAsyncoff-thread).Each call re-runs render and diff (CPU cost). In Blazor Server every diff crosses the circuit, so frequent calls can flood the connection and lag the UI.
Avoid calling it in tight loops: batch changes and call once, throttle high-frequency sources, and use
ShouldRenderto suppress no-op renders.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/rendering?view=aspnetcore-10.0
- https://github.com/dotnet/aspnetcore/discussions/29318
- https://www.coder000.com/post/blazor-current-thread-is-not-associated-with-the-dispatcher-invokeasync
- https://learn.microsoft.com/en-us/aspnet/core/blazor/performance/rendering?view=aspnetcore-10.0
- https://arnasoftech.com/blazor-web-application-development/
- https://blazor-university.com/components/multi-threaded-rendering/invokeasync/
- https://medium.com/@syeedmdtalha/shouldrender-and-statehaschanged-in-blazor-mastering-ui-rendering-control-9dd4509eed20
- https://visitkans.medium.com/why-statehaschanged-didnt-update-my-ui-and-how-i-fixed-it-without-losing-my-mind-d283b3766ceb