This code will help you to understand how to refresh a page automatically at specific time interval.
In Blazor, “StateHasChanged” is used to re-render a page. When changes are detected in components, a page is refreshed. In the following example, a button click increments the count on time interval automatically.
@using System.Threading; <p>Current count: @currentCount</p> <button class="btn btn-primary" @onclick="IncrementCount">Click me</button> @code { private int currentCount = 0; private void IncrementCount() { var timer = new Timer(new TimerCallback(_ => { currentCount++; InvokeAsync(() => { StateHasChanged(); }); }), null, 1000, 1000); } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
In Blazor, “StateHasChanged” is used to re-render a page. When changes are detected in components, a page is refreshed. In the following example, a button click increments the count on time interval automatically.
need an explanation for this answer? contact us directly to get an explanation for this answer