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.

[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

Related FAQs

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

Please submit your question and answer.