Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda