To perform the wait operation in Blazor, we need to use Task.Delay(Time in milliseconds) which will wait for the specified time before execution.
In the sample, we have delayed the count increment by a second by using the Task.Delay() method.
[counter.razor]
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="@(async () => await Increment())">Click me</button>
@code {
private int currentCount = 0;
async Task Increment()
{
await Task.Delay(1000);
currentCount++;
}
}
Share with