Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

i have a blazor app for factory layout and i want to make the functionality of reloading every 15 seconds but it doesn't work

$
0
0

i've tried PeriodicTimer and jsinterop but both doesn't achieve the desired behaviour

here's my @code block that outputs no errors, exception nor the expected bahaviour

@code {public List<Station> Stations = new List<Station>();private List<Connection> Connections = new List<Connection>();private List<CurvedConnection> CurvedConnections = new List<CurvedConnection>();private List<string> LineElements = new List<string>();private PeriodicTimer periodicTimer;private CancellationTokenSource _cts = new CancellationTokenSource();private DateTime currentTime = DateTime.Now;private bool isInitialized = false;protected override void OnInitialized(){    SetupInitialStations();    UpdateConnections();}protected override async Task OnAfterRenderAsync(bool firstRender){    if (firstRender)    {        isInitialized = true;        periodicTimer = new PeriodicTimer(TimeSpan.FromSeconds(15));        while (await periodicTimer.WaitForNextTickAsync(_cts.Token))        {            await JS.InvokeVoidAsync("reloadPage");            await JS.InvokeVoidAsync("console.log", "Periodic work done", currentTime);        }    }public void Dispose(){    _cts.Cancel();    periodicTimer?.Dispose();}}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>