Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
Blazor Server Loading Indicator

Why loading indicator doesn't show by default in Blazor Server application?

I've created a Blazor Server app using standard template with WeatherForecastService in it.

I've added Thread.Sleep(2000) at the beginning of GetForecastAsync method to simulate long time operation.

Result is that I don't see FetchData page until 2 seconds tick away.

On the other hand if I put await Task.Run in FetchData.razor like below:

protected override async Task OnInitializedAsync()
    {
        base.OnInitializedAsync();
      

        //forecasts = await ForecastService.GetForecastAsync(DateTime.Now); //not working as should?
        await Task.Run(LoadData);   //works fine
}

async Task LoadData(){
       forecasts = await ForecastService.GetForecastAsync(DateTime.Now); 
}

Then I see the "Loading...".

Is something not right with the default FetchData or am I doing something wrong?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The UI has to run on 1 Thread. When you Sleep() on that thread then there is no UI for the duration.

With Task.Run() you move LoadData() to another Thread so the show can go on. But that only works for Blazor Server. On WebAssembly there are no 'other' threads.

Sleep() can be used to simulate synchronous (CPU intensive) work.
Task.Delay() simulates asynchronous I/O.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda