Live Chat Icon For mobile
Live Chat Icon

How can I perform asynchronous calls in a Blazor application?

Platform: Blazor| Category: General

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();

}

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.