I have a component that needs to display fresh data every 1 minute.
I tried the new timer (Periodic Timer) and it works fine.
Now, my questions are,
Where is the best place to put the while loop?
Is something else required for a proper dispose of the PeriodicTimer?
public partial class Index:IDisposable{ private readonly PeriodicTimer _periodicTimer = new(TimeSpan.FromMinutes(1)); protected override async Task OnInitializedAsync() { await Service.Init(); while (await _periodicTimer.WaitForNextTickAsync()) { await Service.GetViewModels(); await InvokeAsync(StateHasChanged); } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { _periodicTimer.Dispose(); } }}