Live Chat Icon For mobile
Live Chat Icon

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

Platform: Blazor| Category : General, Tips and Tricks

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 {
    public int Timer { get; set; } = 5;

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

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

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.