I gather that you are using this code example:
Blazor: Timer Example - Refresh Data - PROWARE technologies[
^]
Your lambda method is calling a remote endpoint. When offline, it will fail. So the Timer is working, just the data is not refreshed. You can check this by setting a breakpoint on the line:
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
The timer will execute the lambda method every two seconds.
You can check it by using this code:
@page "/"
<h1>Tick Count: @tickCount</h1>
@code {
private int tickCount = 0;
private Timer? timer;
protected override Task OnInitializedAsync()
{
timer = new Timer(stateInfo =>
{
tickCount += 1;
InvokeAsync(StateHasChanged);
}, new AutoResetEvent(false), 2000, 2000);
return base.OnInitializedAsync();
}
}
When run, the Tick Count will update every 2 seconds.