I’m rather new to Blazor, but not to OO languages
I’ve got a web service that has a controller that returns requests from a repository
I have a UI service that is independent and calls the web service
I’m trying to update a table periodically with the results of the get from the web service
@page "/"
@using System.Timers
@using WebServices
@inject StatusService WebService // Has a httpClient to call web service
@inject IConfiguration Configuration
<h4>Status Viewer</h4>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>Last Update</th>
</tr>
</thead>
<tbody>
@if (StatusList != null)
{
@foreach (var status in StatusList)
{
<tr>
<td>@status.Name</td>
<td>@status.Status</td>
<td>@status.Timestamp</td>
</tr>
}
}
</tbody>
</table>
@code
{
public IEnumerable<Status> StatusList { get; set; }
private int UIReloadTime;
private const int MINUTE_IN_MILLISECONDS = 60000;
private System.Timers.Timer Timer { get; set; }
protected override async Task OnInitializedAsync()
{
UIReloadTime = int.Parse(Configuration.GetValue<string>("ui:ReloadTime"));
await UpdateStatus();
Timer = new System.Timers.Timer();
Timer.Interval = (UIReloadTime * MINUTE_IN_MILLISECONDS);
Timer.Elapsed += OnElapsed;
Timer.Enabled = true;
Timer.Start();
}
private async void OnElapsed(object? sender, ElapsedEventArgs e)
{
await UpdateStatus();
}
private async Task UpdateStatus()
{
StatusList = await WebService.GetStatus();
await InvokeAsync(StateHasChanged);
}
}
I get a valid value during the init process, but after that, nothing.
I know it is something to do with the rerendering, but I do not know how to trigger it that is different to how I am doing it now
I am using the server side rendering, not sure if I’m trying to do a WASM thing with the server rendering
I’ve tried the PeriodicTimer, the Threading.Timer and been trying things for about 2 days now and nothing works
I’ve also attempted to implement IDisposable with the Timer types, but dispose is always called