Loading, please wait...

A to Z Full Forms and Acronyms

How can I perform asynchronous calls in a Blazor application?

This code will help you to understand how to perform asynchronous calls in a Blazor application. to

We can perform asynchronous calls in a Blazor application using async and await keywords for calling any asynchronous Task or performing any operation.

Refer to the following code snippet.

[Index.razor]

@page "/"

<button @onclick="Compare">Compare</button>
<br />
<p>@content</p>

@code {

    public string content = "Some Text";

    public async void  Compare()
    {
        await Task.Run(() => TimeOutMethod());
        content = "";
        await Task.CompletedTask;
        
    }

    void TimeOutMethod() => Task.Delay(3000).Wait();

}
A to Z Full Forms and Acronyms

Related Article