Open ViRuSTriNiTy opened 10 hours ago
Hi there,
as the title already states, QuickGrid possibly throws an InvokeAsync exception when RefreshDataAsync() is invoked from a callback associated with a background service, like a timer.
QuickGrid
InvokeAsync
RefreshDataAsync()
This is caused by a call to StateHasChanged() within RefreshDataAsync() without wrapping it in InvokeAsnyc as described in https://learn.microsoft.com/en-us/aspnet/core/blazor/components/synchronization-context?view=aspnetcore-8.0#invoke-component-methods-externally-to-update-state.
StateHasChanged()
InvokeAsnyc
My current solution is to catch the exception and call StateHasChanged() with InvokeAsync otherwise rethrow:
try { await Grid.RefreshDataAsync(); } catch (InvalidOperationException ex) { if (ex.Message.Contains("InvokeAsync", StringComparison.Ordinal)) await InvokeAsync(StateHasChanged); else throw; }
It would be nice to have await InvokeAsync(StateHasChanged) calls in QuickGrid to avoid the need to use try catches here and there.
await InvokeAsync(StateHasChanged)
try catches
No response
@ViRuSTriNiTy thanks for contacting us.
It's not clear what you are asking. Are you suggesting that RefreshDataAsync internally dispatches the call via InvokeAsync?
RefreshDataAsync
Is there an existing issue for this?
Describe the bug
Hi there,
as the title already states,
QuickGrid
possibly throws anInvokeAsync
exception whenRefreshDataAsync()
is invoked from a callback associated with a background service, like a timer.This is caused by a call to
StateHasChanged()
withinRefreshDataAsync()
without wrapping it inInvokeAsnyc
as described in https://learn.microsoft.com/en-us/aspnet/core/blazor/components/synchronization-context?view=aspnetcore-8.0#invoke-component-methods-externally-to-update-state.My current solution is to catch the exception and call
StateHasChanged()
withInvokeAsync
otherwise rethrow:Expected Behavior
It would be nice to have
await InvokeAsync(StateHasChanged)
calls inQuickGrid
to avoid the need to usetry catches
here and there.Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response