Q:

ow to delay a task in Blazor without blocking the UI?

0

This code will help you to understand how to delay a task in Blazor without blocking the UI.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

You can delay a task in Blazor by using the Task.Delay() method where the time set for the task to be delayed before proceeding to the next.

<h3>Timer: @Timer</h3>

@code {
    [Parameter] 
    public int Timer { get; set; } = 5;

    public async void StartTimerAsync()
    {
        while (Timer > 0)
        {
            Timer--;
            StateHasChanged();
            await Task.Delay(1000);
        }
    }

    protected override void OnInitialized()
        => StartAsync();
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now